Here is a question on OOPS concepts like Inheritance and Default Constructor. The code provided is in C#.
There are three classes named A, B and C.
Class A has a default constructor that writes "In A" to console. Similarly Class B and C has default constructors that write "In B", and "In C" to Console respectively.
Class C inherits from Class B and Class B inherits from class A.
[Code]
class A
{
public A()
{
Console.WriteLine("In A");
}
}
class B:A
{
public B()
{
Console.WriteLine("In B");
}
}
class C:B
{
public C()
{
Console.WriteLine("In C");
}
}
[/Code]
Now, the question is as below.
If we instanciate class C, what will be the output.
[Code]
static void Main(string[] args)
{
C objC = new C();
Console.Read();
}
[/Code]
Result:
The result will be:
In A
In B
In C
There are three classes named A, B and C.
Class A has a default constructor that writes "In A" to console. Similarly Class B and C has default constructors that write "In B", and "In C" to Console respectively.
Class C inherits from Class B and Class B inherits from class A.
[Code]
class A
{
public A()
{
Console.WriteLine("In A");
}
}
class B:A
{
public B()
{
Console.WriteLine("In B");
}
}
class C:B
{
public C()
{
Console.WriteLine("In C");
}
}
[/Code]
Now, the question is as below.
If we instanciate class C, what will be the output.
[Code]
static void Main(string[] args)
{
C objC = new C();
Console.Read();
}
[/Code]
Result:
The result will be:
In A
In B
In C