
// define superclass
class Shape {
	private String name;
	protected double area;

	public Shape() {
		System.out.println("Shape constructor...");
		name = "noname";
	}

	public Shape(String n) {
		System.out.println("Shape constructor with parameter...");
		name = n;
	}

	public double getArea() {
		return area;
	}
}

// define subclass
class Square extends Shape {
	private int width;
	private int height;

	public Square(int w, int h) {
		// implicitly call superclass constructor that takes no parameter
		System.out.println("Square constructor...");
		width = w;
		height = h;
	}

	// overloaded constructor
	public Square(int w, int h, String n) {
		// call superclass constructor that takes 1 parameter
		super(n);
		System.out.println("Square constructor with 3 parameters...");
		width = w;
		height = h;
	}

	public void calculateArea() {
		area = width * height;
	}
}

public class InheritanceExample {
	public static void main(String[] args) {
		Square s1 = new Square(10, 20);
		s1.calculateArea();
		System.out.println("The area for s1 is " + s1.getArea());

		Square s2 = new Square(12, 22, "s2");
		s2.calculateArea();
		System.out.println("The area for s2 is " + s2.getArea());
		System.out.println();
		
		System.out.println(s1);
		System.out.println(s2);
	}
}
