public Animal{
private String name;
private int age;
private String color;
public Animal(){}
public Animal(String name,int age,String color){
this.name = name;
this.age = age;
this.color = 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 String getColor(){
return color;
}
public void setColor(String color){
this.color = color;
}
public void eat(){
System.out.println("我喜欢吃好吃的~");
}
public void show(){
System.out.println("我叫"+getName()+"今年"+getAge()+"岁了,"+"我是"+getColor()+"颜色的。");
}
}
class Cat extends Animal{
public Cat(){}
public Cat(String name,int age,String color){
super(name,age,color);
}
public void playGame(){
System.out.println("我喜欢玩儿游戏~");
}
}
class Dog extends Animal{
public Dog(){}
public Dog(String name,int age,String color){
super(name,age,color);
}
public void lookDoor(){
System.out.println("我要把门看好~");
}
}
class Demo{
public static void main(String[] args){
//方式一:
Cat c = new Cat();
c.setName("咪咪");
c.setAge(3);
c.setColor("黑色");
c.show();
System.out.println("----------");
Dog d = new Dog();
d.setName("大黄");
d.setAge(2);
d.setColor("橘黄色");
d.show();
System.out.println("----------");
System.out.println("----------");
//方式二:
Cat c = new Cat("咪咪",3,"黑色");
Dog d = new Dog("大黄",2,"黄色");
c.show();
d.show();
}
}