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();
AnimalTools.printAnimal(d);
AnimalTools.printAnimal(d2);
AnimalTools.printAnimal(d3);
}
} |
|