I have some code to implement interface in C#
public interface Intfc { void xyz();}
public class BaseClass : Intfc
{
public virtual void xyz()
{
Console.WriteLine("In Base Class");
}
}
public class Derived : BaseClass
{
public override void xyz()
{
Console.WriteLine("In Derived Class");
}
}
static void Main(string[] args)
{
Derived mc = new Derived();
mc.xyz(); //In Derived Class
((BaseClass)mc).xyz(); //In Base Class
((Intfc)mc).xyz(); //In Derived Class
Console.ReadKey();
}
I need the console output as provided in comments in Main()
.
Actual results are
In Derived Class
In Derived Class
In Derived Class
How can I achieve the desired results.