Notes for Java Abstract Class and Interface

Notes for Java Abstract Class and Interface

Notes for abstract class and interface:

public class ReviewQuestions {
	public static void main(String[] args) {
		new Circle9();
	}	
}

abstract class GeometricObject {
	protected GeometricObject() {
		System.out.print("A");
	}
	protected GeometricObject(String color, boolean filled) {
		System.out.print("B");
	}
}

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");
	}
}

Output would be BEDC because the non default constructor in the super class GeometricObject is called from the third
constructor of Circle9 class. However, if the third constructor is not called, Java system will insert a call to the default 
constructor of GeometricObject right before this(1.0) in the default constructor of Circle9. In a nutshell, the constructor
of superclass is called only once when creating a child object.
			
		Number[] numberArray = new Integer[2];
		numberArray[0] = new Double(1.5);
		
		The first line is OK because it creates an array of two Integer objects and assign to super class type Number.
		The second line causes run-time error because numberArray[0] is an object of Integer type (that is its actual 
		data type) and it cannot be assigned to a sibling object (new Double(1.5)). However, the following is fine:
		Number num = new Double(1.5); Number is a super data type.