标题: 如下题,子父类继承中、代码在内存中加载顺序如何? [打印本页] 作者: 一江夜雨 时间: 2015-11-16 22:23 标题: 如下题,子父类继承中、代码在内存中加载顺序如何? 请问该程序的运行结果是什么?
class SuperEx {
String s = "父类成员变量";
public void method(){
System.out.println("SupMethod");
}
}
class SubEx extends SuperEx {
String s = "子类成员变量";
public void method(){
System.out.println("SubMethod");
}
}
class Demo {
public static void main (String[] args) {
SubEx sub = new SubEx();
SuperEx sup = new SubEx();
System.out.println(sub.s);
function( sub );
System.out.println(sup.s);
function( sup );
}
public static void function (SuperEx sup) {
sup.method();
}
}