Client.class
public class Client{
public static void main(String[] args){
Person p = new Person();
Dog d = new Dog();
Cat c = new Cat();
p.feed(d);
p.feed(c);
}
}
---------------------------------------------------------------------------------------------------------------------------------------------
Person.class
public class Person{
// 养狗
public void feed(Dog d){
d.eat();
}
// 养猫
public void feed(Cat c){
c.eat();
}
}
//养别的
}
-----------------------------------------------------------------------------------------------------------------------------
Dog.class
public class Dog {
//Method
public void eat(){
System.out.println( "狗吃肉" );
}
}
---------------------------------------------------------------------------------------------------------------------------------
Cat.class
public class {
//Method
public void eat(){
System.out.println( "猫吃鱼" );
}
}