abstract class Animal { //动物类(父类)
private String name ;
private int age;
public abstract void eat() ;
public abstract void sleep();
public Animal(){}
public Animal(String name,int age){
this.name = name;
this.age = age;
}
public void setName() {
}
public String getName(){
return name;
}
public void setAge( int age){
this.age = age;
}
public int getAge(){
return age;
}
public void show(){
System.out.println(getAge()+"\n"+getName());
}
}
class JumpCat extends Animal implements Jumping { //猫类(继承动物)
public void eat() {
System.out.println("猫吃鱼");
}
public JumpCat(){}
public JumpCat(String name, int age){
super(name,age);
}
public void sleep(){
System.out.println("猫是白天睡觉的");
}
public void show(){
System.out.println(getAge()+"\n"+getName());
}
public void jump(){
System.out.println("猫进训练营后学会跳高");
}
}
class JumpDog extends Animal implements Jumping { //狗类(继承动物)
public JumpDog(){}
public JumpDog(String name, int age){
super(name,age);
}
public void eat(){
System.out.println("狗,吃肉");
}
public void sleep(){
System.out.println("狗白天睡觉,晚上守夜");
}
public void show(){
System.out.println(getAge()+"\n"+getName());
}
public void jump(){
System.out.println("狗进训练营后学会跳高");
}
}
class DemoAnimal { //测试
public static void main(String[] args){
Animal d = new JumpDog("中华田园犬",10);
d.show();
d.eat();
d.sleep();