读书人

类的继承和多态解决方法

发布时间: 2012-03-01 10:25:47 作者: rapoo

类的继承和多态
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()调用父类的,逐步运行出来就是了!

读书人网 >J2SE开发

热点推荐