class Demo {
public static void main(String[] args) {
Dog dog = new Dog();
AnimalTools.print(dog);
/*
dog.eat();
dog.drink();
dog.la();
dog.sa();
dog.sleep();
*/
Cat cat = new Cat();
AnimalTools.print(cat);
/*
cat.eat();
cat.drink();
cat.la();
cat.sa();
cat.sleep();
*/
Pig pig = new Pig();
AnimalTools.print(pig);
/*
pig.eat();
pig.drink();
pig.la();
pig.sa();
pig.sleep();
*/
}
}
class Dog extends Animal {
public void eat() {
System.out.println("吃骨头");
}
public void drink() {
System.out.println("狗喝");
}
public void la() {
System.out.println("狗拉");
}
public void sa() {
System.out.println("狗撒");
}
public void sleep() {
System.out.println("狗睡");
}
}
class Cat extends Animal {
public void eat() {
System.out.println("吃鱼");
}
public void drink() {
System.out.println("猫喝");
}
public void la() {
System.out.println("猫拉");
}
public void sa() {
System.out.println("猫撒");
}
public void sleep() {
System.out.println("猫睡");
}
}
class Pig extends Animal {
public void eat() {
System.out.println("吃肉");
}
public void drink() {
System.out.println("猪喝");
}
public void la() {
System.out.println("猪拉");
}
public void sa() {
System.out.println("猪撒");
}
public void sleep() {
System.out.println("猪睡");
}
}
class Animal {
String name;
int age;
public void eat() {
System.out.println("吃");
}
public void drink() {
System.out.println("喝");
}
public void la() {
System.out.println("拉");
}
public void sa() {
System.out.println("撒");
}
public void sleep() {
System.out.println("睡");
}
}
class AnimalTools {
public static void print(Animal animal) {//Animal aniaml = new Dog();
animal.eat(); //Animal aniaml = new Cat();
animal.drink(); //Animal aniaml = new Pig();
animal.la();
animal.sa();
animal.sleep();
}
} |
|