I have the following code:
class Animal
{
public virtual void Invoke()
{
Console.WriteLine("Animal");
}
}
class Dog : Animal
{
public override void Invoke()
{
Console.WriteLine("Dog");
}
}
class Dobberman : Dog
{
public new void Invoke()
{
Console.WriteLine("Dobberman");
}
}
class Program
{
static void Main(string[] args)
{
Animal dog = new Dobberman();
dog.Invoke();
Dobberman dog2 = new Dobberman();
dog2.Invoke();
}
}
Why would it print "Dog" in the first output? and why "Dobberman" in the second? What is going on under the hood?