Thursday, 12 September 2013

Abstract class: output of this code

Abstract class: output of this code

Currently doing a practice test on abstract classes and interfaces and ran
into this problem:
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");
}
}
Why is the output BEDC? I thought new Circle9() would first invoke the
no-arg constructor of the Circle 9 class, printing A, and then the other
letters, but I'm having a hard time understanding the path of the code.

No comments:

Post a Comment