Java中 方法的多态 简析图
代码如下:
public class Client{
public static void main(String[] args){
Person p = new Person();
Dog d = new Dog();
Cat c = new Cat();
p.feed(d);
}
}
public class Person{
public void feed(Animal a){
a.eat();
}
}
public class Animal{
public void eat(){
}
}
public class Dog extends Animal{
//Method
public void eat(){
System.out.println( "狗吃肉" );
}
}
时间仓促,如有遗漏,敬请指教!