class A {
void fun1() {
System.out.println(fun2());
}
int fun2() {
return 123;
}
}
public class B extends A {
int fun2() {
return 456;
}
public static void main(String args[]) {
B b = new B();
b.fun1();
A a = b;
a.fun1();
}
}
*
* */
作者: tinyvampire 时间: 2015-3-21 23:51
A a=b;这是多态,B.fun1()运行之后,fun2()就被复写,所以再次调用fun2()时的输出结果456了.