class A {
public void print(A a) {
System.out.println("A");
a.add();
}
public void add() {
System.out.println("At A.add()");
}
}
class B extends A {
public void print(B b) {
System.out.println("B");
b.add();
}
public void add() {
System.out.println("At B.add()");
}
}
public class MDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
A a = new B();
a.print(a);
;
}
}
输出
A
At B.add()
请澄清输出。 参考来自 Selecting overriding method java with multiple options