public class Demo5 {
public static void main(String[] args) {
/*Cat cat1=new Cat();
Dog dog1=new Dog();
cat1.cry();*/
//多态性
/*Animal an=new Cat();
Food f=new Food();
an.cry();
an=new Dog();
an.cry();
an.eat();
f.showName();*/
Master master=new Master();
master.feed(new Dog(),new Bond());
}
}
class Food{
String name;
public void showName(){
}
}
class Fish extends Food{
public void showName(){
System.out.println("I'm fish");
}
}
class Bond extends Food{
public void showName(){
System.out.println("I'm bond");
}
}
class Master{
public void feed(Animal an,Food f){
an.eat();
f.showName();
}
}
class Animal
{
String name;
int age;
public void cry(){
System.out.println("I don't know cry");
}
public void eat(){
System.out.println("I don't know eat");
}
}
class Dog extends Animal{
public void cry(){
System.out.println("wang wang");
}
public void eat(){
System.out.println("I eat bone");
}
}
class Cat extends Animal{
public void cry(){
System.out.println("miao miao");
}
public void eat(){
System.out.println("I eat fish");
}
}