I have multilevel inheritance of 3 classes
class Product1
{
public virtual void Show()
{
Console.WriteLine("Product1.show");
}
}
class Product2 : Product1
{
public override void Show()
{
Console.WriteLine("Product2.show");
}
}
class Product3 : Product2
{
public new void Show()
{
Console.WriteLine("Product3.show");
}
}
At the time of object creation, I'm assigning object of Product3 to Product1.
class Products
{
static void Main()
{
Product1 product1 = new Product1();
Product3 product3 = new Product3();
product1 = product3;
product3.Show();
product1.Show();
}
}
And called Show method. I thought in both the cases the answer would be Product3.show but not sure how Product2.show is being called.
Any help on the explanation would be appreciated :)