标题: 多态有什么实际用处?求解答 [打印本页] 作者: WilliCicci 时间: 2015-7-18 00:38 标题: 多态有什么实际用处?求解答 class Animal{
public void eat(){
System.out.println("吃");
}
public void drink(){
System.out.println("喝");
}
}
class Dog extends Animal {
public void eat(){
System.out.println("吃骨头");
}
public void drink(){
System.out.println("狗喝");
}
}
class Cat extends Animal {
public void eat(){
System.out.println("吃鱼");
}
public void drink(){
System.out.println("猫喝");
}
}
class AnimalTools{
private AnimalTools(){}
public static void printAnimal(Animal a){
a.eat();
a.drink();
}
}
class AnimalTest09 {
public static void main(String[] args) {
Dog d = new Dog();
Dog d2 = new Dog();
Dog d3 = new Dog();