class Abstract_Animal_Text{
public static void main(String[] args) {
Animal a = new Cat("小白",2);
Animal b = new Dog("旺财",3);
System.out.print(a.getName());
a.eat();
System.out.print(b.getName());
b.eat();
//a.catchMouse();
//b.lookHome();
}
}
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 name;
}
public void setAge (int age){
this.age = age;
}
public int getAge(){
return age;
}
abstract public void eat();
}
class Cat extends Animal {
public Cat(){}
public Cat(String name,int age){
super(name,age);
}
public void catchMouse(){
System.out.println("抓老鼠");
}
public void eat(){
System.out.println("吃鱼");
}
}
class Dog extends Animal {
public Dog(){}
public Dog(String name,int age){
super(name,age);
}
public void lookHome(){
System.out.println("看家");
}
public void eat(){
System.out.println("吃肉");
}
}
|