class Animal {
//姓名
private String name;
//年龄
private int age;
//颜色
private String color;
public 【1】 () {}
public Animal(String name,int age,String color) {
this.name = name;
this.age = age;
【2】= color;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public 【3】 getColor() {
【4】 color;
}
public void setColor(String color) {
this.color = color;
}
public void eat() {
System.out.println("不要睡了,该吃饭了");
}
}
//定义猫类继承动物类
class Cat extends Animal {
public Cat() {}
public Cat(String name,int age,String color) {
【5】 (name,age,color);
}
public void playGame() {
System.out.println("猫玩英雄联盟");
}
}
//定义狗类继承动物类
class Dog extends Animal {
public Dog() {}
public 【6】 (String name,int age,String color) {
super(name,age,color);
}
public void lookDoor () {
System.out.println("狗看家");
}
}
public class ExtendsTest5 {
public static void main(String[] args) {
//测试猫
Cat c1 = new Cat();
c1.setName(“Tom”);
c1.setAge(3);
c1.setColor(“白色”);
System.out.println(“猫的名字是:”+c1. 【7】+";年龄是:"+c1.getAge()+";颜色是:"+c1.getColor());
c1.eat();
c1. 【8】 ();
System.out.println("---------------");
//方式2
Cat c2 = new 【9】 ("杰瑞",5,"土豪金");
System.out.println("猫的名字是:"+c2.getName()+";年龄是:"+c2.getAge()+";颜色是:"+c2. 【10】);
c2.eat();
c2.playGame();
}
}