class Rectangle { Rectangle(int w, int h) { this.width = w; this.height = h; } // Yields a rectangle with aspect ratio 2:1 Rectangle(int h) { // height = h; // width = 2*h; this(2*h, h); } public String toString() { String str1 = "I am a rectangle of width " + width + " and height " + height + ". My area is " + Area(); return str1; } private int Area() { return (width*height); } public int getWidth() { // int foo; // foo=foo+1; // not initialized return width; } private int width; private int height; // public static final double pi = 3.14; } class Square extends Rectangle { Square(int side) { // width = side; // height = side; super(side,side); } public String toString() { return "I am a square!!!" + super.toString(); } } public class OOPDemo { public static void main(String args[]) { Rectangle rec1 = new Rectangle(new Integer(10),4); Rectangle rec2 = new Rectangle(5,6); Rectangle rec3 = new Rectangle(8); System.out.println(rec1); System.out.println(rec2); // rec1.Area(); System.out.println(rec1.getWidth()); System.out.println(rec3); Square sqr1 = new Square(15); System.out.println(sqr1); } }