class Super {
public int getLength() {return 4;}
}
public class Sub extends Super {
public int getLength() {
return 5;
}
public static void main (String[]args) {
Super sooper = new Super ();
Super sub = new Sub();
System.out.println(sooper.getLength()+ "," + sub.getLength() );
}
}A. 4, 4
B. 4, 5
C. 5, 4
D. 5, 5
E. 代码不能被编译
楼下的分析下,选哪个,为什么?
public int getLength() {return 4;}
}
public class Sub extends Super {
public int getLength() {
return 5;
}
public static void main (String[]args) {
Super sooper = new Super ();
Super sub = new Sub();
System.out.println(sooper.getLength()+ "," + sub.getLength() );
}
}A. 4, 4
B. 4, 5
C. 5, 4
D. 5, 5
E. 代码不能被编译
楼下的分析下,选哪个,为什么?
这个就不解释了 4sub.getLength() ;
---》Super sub = new Sub();
父类引用子类对象,在执行中断定为使用子类方法。
事实证明答案是B 4,5
学习中....
Super 和 super是有区别的。
super是关键字;Super不是。
出题人真实目的不是写了这么多,就为了考个关键字吧,真的那样也太考试化了,也只有大学才会做的,
公司是不会这样的。