建立TestInstance 类,在类中定义方法method1(Person e); 在method1中: 根据e的类型调用相应类的getInfo()方法。

img


建立TestInstance 类,在类中定义方法method1(Person e);

在method1中: 根据e的类型调用相应类的getInfo()方法。

package application.test;

public class TestInstance  {
    
     public void method1(Person p) {
         System.out.println(p.getInfo());
     }

    public static void main(String[] args) {
        TestInstance  t = new TestInstance ();
        t.method1(new Person());
        t.method1(new Student());
        t.method1(new Graduate());
    }
}

上面不是代码都写好了吗?只要调用一下就好了。

img