class Test2_Animal {
public static void main(String[] args) {
Cat c1=new Cat();
c1.Eat();
c1.catchMouse();
}
}
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;
}
public abstract void Eat();
}
class Cat extends Animal {
public Cat(){}
public Cat(String name,int age){
super(name,age);
}
public void Eat(){
System.out.println("吃鱼");
}
public void catchMouse(){
System.out.println("抓老鼠");
}
}
class Dog extends Animal{
public Dog(){}
public Dog(String name,int age){
super(name,age);
}
public void Eat(){
System.out.println("吃屎");
}
public void lookHome(){
System.out.println("看家");
}
} |
|