could you please tell me why the result of the code below is BaseClass::method
?
I was thinking that DerivedClass2 will just override the virtual method of DerivedClass1 which is declared as new, meaning that the BaseClass method is not used. Or since the DerivedClass2 overrides a virtual method of DerivedClass1, then there's dynamic binding which will call the DerivedClass2 method version and not the one of DerivedClass1 or BaseClass. Any help? What's wrong with my reasoning? thanks
class BaseClass
{
public void method() { Console.WriteLine("BaseClass::method"); }
}
class DerivedClass1 : BaseClass
{
public new virtual void method() { Console.WriteLine("DerivedClass1::method"); }
}
class DerivedClass2 : DerivedClass1
{
public override void method(){ Console.WriteLine("DerivedClass2::method"); }
}
class Program
{
static void Main(string[] args)
{
BaseClass e = new DerivedClass2();
e.method();//BaseClass::method. But Why???
Console.ReadLine();
}
}