Author : Rahul
What will be the output of below program.
Code
using System;
namespace InterviewQuestion
{
public class BaseClass1
{
public virtual void Method1()
{
Console.WriteLine("Inside BaseClass1 : Method1.");
}
}
public class DerivedClass1 : BaseClass1
{
public override void Method1()
{
Console.WriteLine("Inside DerivedClass1 : Method1.");
}
}
public class DerivedClass2 : DerivedClass1
{
public override void Method1()
{
Console.WriteLine("Inside DerivedClass2 : Method1.");
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("For First case:");
BaseClass1 baseClass1 = new DerivedClass2();
baseClass1.Method1();
Console.WriteLine("For Second case:");
DerivedClass1 baseClass2 = new DerivedClass2();
baseClass2.Method1();
}
}
}
Output
For First case:
Inside DerivedClass2 : Method1.
For Second case:
Inside DerivedClass2 : Method1.