第一次靠自己把java内存图画好还是挺有成就感的,虽然有老师帮助.第一次发,勿喷.....

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( "猫吃鱼" );
    }

}

原文地址:https://www.cnblogs.com/lwxalxy/p/4364207.html