请问该程序的运行结果是什么?
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();
}
} |
|