學(xué)習(xí)多態(tài)時(shí)看到如下一個(gè)例子: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(); } }問(wèn)題是:最后三個(gè)實(shí)例化的語(yǔ)句怎樣理解?。浚ㄕf(shuō)詳細(xì)點(diǎn)?。┏绦蜻\(yùn)行結(jié)果為:Animal eat...Animal eat...Cat eat... 為什么???
- 1 回答
- 0 關(guān)注
- 463 瀏覽
添加回答
舉報(bào)
0/150
提交
取消