abstract class Zoou{
String colour;
String dwu;
public Zoou(){}
public Zoou(String dwu,String colour){
this.dwu = dwu;
this.colour = colour;
}
public void colour(){
System.out.println(dwu+"的毛是"+colour+"色的");
}
public void Pao(){
System.out.println("跑得快");
}
public abstract void show();
}
class Cat extends Zoou
{
public Cat(String colour,String dwu){
super(colour,dwu);
}
public void show(){
System.out.println(super.dwu+"喜欢吃鱼");
}
}
class Dog extends Zoou
{
public Dog(String colour,String dwu){
super(colour,dwu);
}
public void show(){
System.out.println(super.dwu+"喜欢吃鱼");
}
}
class Pig extends Zoou
{
public Pig(String colour,String dwu){
super(colour,dwu);
}
public void show(){
System.out.println(super.dwu+"喜欢吃shiliao");
}
}
class AnimalFoo
{
private AnimalFoo(){}
public static void print(Zoou p){
p.colour();
p.Pao();
p.show();
}
}
class ZoonDemo{
public static void main(String[] args){
Dog dog = new Dog("狗","黄");
AnimalFoo.print(dog);
Cat cat = new Cat("猫","黑");
AnimalFoo.print(cat);
Pig p = new Pig("猪","黑白");
AnimalFoo.print(p); |
|