What will be the output of the following code ?

using System;
public class BaseClass
{
public BaseClass()
{
Console.WriteLine("You are in Base Class of DotNetFunda");
}
}
public class ChildClass : BaseClass
{
public ChildClass()
{
Console.WriteLine("You are in Child Class of DotNetFunda");
}
static void Main()
{
ChildClass CC = new ChildClass();
}
}

 Posted by Chvrsri on 3/24/2011 | Category: C# Interview questions | Views: 6161 | Points: 40
Answer:



You are in Base Class of DotNetFunda
You are in Child Class of DotNetFunda

This is because the Base classes are automatically instantiated before derived classes. If we could the see the output, The BaseClass constructor executed before the ChildClass constructor.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Questpond on: 3/25/2011 | Points: 10
Below is the video which demonstrates answer for the above question.

http://www.youtube.com/watch?v=_w-VW34cN9I&hd=1
Posted by: Questpond on: 3/25/2011 | Points: 10
Below is the video which demonstrates answer for the above question.

http://www.youtube.com/watch?v=_w-VW34cN9I&hd=1

Login to post response