class Mao {
public static void main(String[] args) {
Cat c1 = new Cat("白",4);
c1.eat();
c1.catchMouse();
System.out.println(c1.getColor()+" "+c1.getLeg());
Dog c2 = new Dog("黑",2);
c2.eat();
c2.lookHome();
System.out.println(c2.getColor()+" "+c2.getLeg());
}
}
class Animal {
String color;
int leg;
public Animal (){}
public Animal(String color ,int leg){
this.color = color;
this.leg = leg;
}
public void setColor(){
this.color = color;
}
public String getColor(){
return color;
}
public void setLeg(){
this.leg = leg;
}
public int getLeg(){
return leg;
}
public void eat(){
System.out.println("吃饭");
}
}
class Cat extends Animal {
public Cat(){}
public Cat(String color,int leg){
super(color,leg);
}
public void catchMouse(){
System.out.println("抓老鼠");
}
}
class Dog extends Animal {
public Dog(){}
public Dog(String color,int leg){
super(color,leg);
}
public void lookHome(){
System.out.println("看家");
}
}
|
|