62,614
社区成员
发帖
与我相关
我的任务
分享
System.out.println(a1.show(b)); //A and A
//没有找到对B类实例的方法,但有其父类A实例的方法,故作为A类实例传入
System.out.println(a1.show(c)); //A and A
//同上
System.out.println(a1.show(d)); //A and D
//A类有对D类实例的方法,作为D类实例传入
System.out.println(a2.show(b)); //B and A
//(父类引用子类对象,只有父类的方法,但B类重写了A类方法)
//父类A没有对B类实例的方法,作为A类实例传入
System.out.println(a2.show(c)); //B and A
//同上
System.out.println(a2.show(d)); //A and D
//下面是B类继承A类,有A,B类方法,B类重写父类对A实例的方法
System.out.println(b.show(a1));//B and A 这个我自己加,为说明方法给重写了
System.out.println(b.show(b)); //B and B
System.out.println(b.show(c)); //B and B
System.out.println(b.show(d)); //A and D
}
}