class Animal{
private Animal(){}
public void eat(){
System.out.println("动物吃饭");
}
public void sleep(){
System.out.println("动物睡觉");
}
}
class Dog extends Animal{
public void eat(){
System.out.println("狗吃肉");
}
public void sleep(){
System.out.println("狗站着睡觉");
}
}
class Pig extends Animal{
public void eat(){
System.out.println("猫吃鱼");
}
public void sleep(){
System.out.println("猫趴着睡觉");
}
}
class Cat extends Animal{
public void eat(){
System.out.println("猪拱白菜");
}
public void sleep(){
System.out.println("猪侧着睡觉");
}
}
class AnimalTool{
AnimalTool(){}
public static void operate(Animal c){
c.eat();
c.sleep();
}
}
class AnimalTest{
public static void main(String[] args){
Dog c1=new Dog();
Dog c2=new Dog();
Dog c3=new Dog();
c1.eat();
c1.sleep();
c2.eat();
c2.sleep();
c3.eat();
c3.sleep();
System.out.println("--------------------------------");
Pig s1=new Pig();
Pig s2=new Pig();
Pig s3=new Pig();
s1.eat();
s1.sleep();
s2.eat();
s2.sleep();
s3.eat();
s3.sleep();
System.out.println("--------------------------------");
Cat n1=new Cat();
Cat n2=new Cat();
Cat n3=new Cat();
n1.eat();
n1.sleep();
n2.eat();
n2.sleep();
n3.eat();
n3.sleep();
System.out.println("--------------------------------");
AnimalTool.operate(c1);
AnimalTool.operate(c2);
AnimalTool.operate(c3);
AnimalTool.operate(s1);
AnimalTool.operate(s2);
AnimalTool.operate(s3);
AnimalTool.operate(n1);
AnimalTool.operate(n2);
AnimalTool.operate(n3);
System.out.println("--------------------------------");
AnimalTool a=new AnimalTool();
a.operate(c1);
System.out.println("--------------------------------");
Animal cc=new Animal();
cc.eat();
cc.sleep();
}
} |
|