interface Shape { // all methods abstract by default public double Area(); static double Pi = 3.14159; } class Circle implements Shape { int radius; Circle(int r) { this.radius = r; } public double Area() { return Pi * radius * radius; } } abstract class Quadrilateral implements Shape { // Any classes that extend Quadrilateral should have a Perimeter // method. abstract int Perimeter(); // concrete method public String toString() { String str = "I am a Quadrilateral of perimeter "+ this.Perimeter() + ", calling Object's toString " + super.toString(); return str; } } class Rectangle extends Quadrilateral { 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() + ";" + super.toString(); return str1; } public double Area() { return (width*height); } public int getWidth() { // int foo; // foo=foo+1; // not initialized return width; } public int Perimeter() { return (2 * width + 2 * height); } 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 OOPDemo2 { 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); Circle cir1 = new Circle(3); System.out.println("The area of cir1 is " + cir1.Area()); } }