class demo_jieKou {
public static void main(String[] args) {
Cat a = new Cat("汤姆",4);
a.eat();
a.sleep();
JumpCat jc = new JumpCat("猫跳高",6);
jc.eat();
jc.sleep();
jc.jump();
}
}
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();
public abstract void sleep();
}
interface Jumping { //跳高的接口
public void jump();
}
class Cat extends Animal {
public Cat() {}
public Cat(String name) {
super(name,age);
}
public void eat() {
System.out.println("猫吃鱼");
}
public void sleep() {
System.out.println("睡觉");
}
}
class JumpCat extends Cat implements Jumping {
public JumpCat() {}
public JumpCat(String name,int age) {
super(name,age);
}
public void jump() {
System.out.println("猫跳高");
}
} |
|