【发布时间】:2016-03-02 21:42:26
【问题描述】:
What is the output of running class Test?
public class Test {
public static void main(String[] args) {
new Circle9();
}
}
public abstract class GeometricObject {
protected GeometricObject() {
System.out.print("A");
}
protected GeometricObject(String color, boolean filled) {
System.out.print("B");
}
}
public class Circle9 extends GeometricObject {
/** No-arg constructor */
public Circle9() {
this(1.0);
System.out.print("C");
}
/** Construct circle with a specified radius */
public Circle9(double radius) {
this(radius, "white", false);
System.out.print("D");
}
/** Construct a circle with specified radius, filled, and color */
public Circle9(double radius, String color, boolean filled) {
super(color, filled);
System.out.print("E");
}
}
谁能详细解释一下为什么这段代码的输出是 BEDC?这是我正在阅读的书中的练习题。我不明白。对我来说,内在性一直是个难题。
【问题讨论】:
-
我投票决定将此问题作为题外话结束,因为“向我解释这一切”不是一个具体的问题陈述。手动或使用调试器检查您的代码,了解多态性是如何工作的,更彻底地阅读您的书,如果在那之后您仍然有一个非常具体的问题,请发布一个新问题。我们不是在这里解释整个主题。
标签: java inheritance abstract-class