class Demo_Animal1{
public static void main(String[] args) {
Cat a = new Cat("加菲",8);
System.out.println(a.getName()+"..."+a.getAge());
a.eat();
a.jump();
Dog b = new Dog("阿扁",10);
System.out.println(b.getName()+"..."+b.getAge());
b.eat();
b.jump();
}
}
//猫 狗
//属性 : name 年龄 吃饭
//特有属性 : 猫吃鱼 狗吃肉
//跳
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 ();
}
interface Jump{
public abstract void jump ();
}
class Cat extends Animal implements Jump{
public Cat (){}
public Cat(String name,int age){
super (name,age);
}
public void eat(){
System.out.println("猫吃鱼");
}
public void jump(){
System.out.println("跳");
}
}
class Dog extends Animal implements Jump{
public Dog(){}
public Dog (String name,int age){
super (name,age);
}
public void eat(){
System.out.println("狗吃肉");
}
public void jump (){
System.out.println("跳");
}
}