public class FifthTest07 {
public static void main(String[] args) {
Master01 zhangsan = new Master01();
Pet01 pet01=new Pet01();
zhangsan.feed(pet01);
Pet02 pet02=new Pet02();
zhangsan.feed(pet02);
Pet03 pet03=new Pet03();
zhangsan.feed(pet03);
}
}
public class Master01 {
public void feed(Pet pet) {
pet.eat();
}
}
public class Pet {
public void eat(){}
}
public class Pet01 extends Pet{
public void eat(){
System.out.println("猫在吃鱼");
}
}
public class Pet02 extends Pet{
public void eat(){
System.out.println("狗在啃骨头");
}
}
public class Pet03 extends Pet{
public void eat(){
System.out.println("老鼠在吃大米");
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201124150420943.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poYW94aWEzODMyNA==,size_16,color_FFFFFF,t_70#pic_center)