类的继承和多态
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 {
/** Default 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
先构建父类,然后构建子类。
[解决办法]
BEDC
关于这种问题,LZ完全可以在IDE里面去运行一下就知道答案了
[解决办法]
BEDC
关于这种问题,LZ完全可以没必要来着上面来问。
[解决办法]
BEDC......this,继续本类构造方法,super()调用父类的,逐步运行出来就是了!