class Test2_Polymorphic {
public static void main(String[] args) {
A a = new B();
a.show();
B b = new C();
b.show();
}
}
class A {
public void show() {
show2();
}
public void show2() {
System.out.println("我");
}
}
class B extends A {
public void show() {
show2();
}
public void show2() {
System.out.println("爱");
}
}
class C extends B {
public void show() {
super.show();
}
public void show2() {
System.out.println("你");
}
}
class Test2_Polymorphic {
public static void main(String[] args) {
A a = new B();
a.show();
B b = new C();
b.show();
}
}
class A {
public void show() {
show2();
}
public void show2() {
System.out.println("我");
}
}
class B extends A {
public void show() {
super.show2();
}
public void show2() {
System.out.println("爱");
}
}
class C extends B {
public void show() {
super.show();
}
public void show2() {
System.out.println("你");
}
}
上面连个代码第二个多了个super,为什么输出的结果上面是"爱 你",下面的是"我 我",
多态运行不是看右边吗?也从写了方法为什么不是输出"爱 你"