学习多态时看到如下一个例子:
public class Animal
{
public virtual void Eat()
{
Console.WriteLine("Animal eat");
}
}
public class Cat : Animal
{
public new void Eat()
{
Console.WriteLine("Cat eat");
}
}
class Tester
{
static void Main(string[] args)
{
Animal a = new Animal();
a.Eat();
Animal ac = new Cat();
ac.Eat();
Cat c = new Cat();
c.Eat();
}
}
问题是:最后三个实例化的语句怎样理解啊?(说详细点啊)
程序运行结果为:
Animal eat...
Animal eat...
Cat eat... 为什么啊?