class Demo4 {
public static void main(String[] args) {
System.out.println("Hello World!");
show(new Cat());
show(new Dog());
}
public static void show(Animal a){
a.eat();
a.run();
}
}
abstract class Animal {
private String name; //姓名
private int age; //年龄
public Animal(){}
public Animal(String name, int age){
this.name = name;
this.age = age;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return this.age;
}
public abstract void eat();
public abstract void run();
}
class Cat extends Animal{
public void eat(){
System.out.println("pppppp");
}
public void run(){
System.out.println("---------");
}
}
class Dog extends Animal{
public void eat(){
System.out.println("ooooo");
}
public void run(){
System.out.println("!!!!!!!!!");
}
} |
|