遇到一个java的多态问题想请教下大神们classAnimal{publicvoidsayHi(){System.out.println("hifromAnimal");}publicvoidlink(Animala){System.out.println("LinkinAnimal");a.sayHi();}}classCatextendsAnimal{publicvoidsayHi(){System.out.println("hifromCat");}publicvoidlink(Catc){System.out.println("LinkfromCat");c.sayHi();}}classMain{publicstaticvoidmain(String[]args){Animala=newCat();Catc=newCat();a.link(c);//LinkfromAnimal\nhifromcata.sayHi();//hifromCat}}
神不在的星期二
相关分类