class A
{
public virtual void WhoAreYou() { Console.WriteLine("I am an A"); }
}
class B : A
{
public override void WhoAreYou() { Console.WriteLine("I am a B"); }
}
class C : B
{
public new virtual void WhoAreYou() { Console.WriteLine("I am a C"); }
}
class D : C
{
public override void WhoAreYou() { Console.WriteLine("I am a D"); }
}
C c = new D();
c.WhoAreYou();// "I am a D"
A a = new D();
a.WhoAreYou();// "I am a B" !!!!
How the reference is allocated internally,reference A contains the reference of B? Can any one explain Whats going On?
new virtual
even make sense conceptually, what is your intended result? – Ashliashlienew
keyword. – Ashliashlieoverride
– Ashliashlienew C()
. – Ashliashlie