class Rectangle { // the Rectangle class has 3 fields int width; int height; Point origin; int id = initializeId(); // add a class variable for the // number of Rectangle objects instantiated static int numberOfRectangles = initNumberOfRectangles(); Rectangle(int initWidth, int initHeight, Point initOrigin) { this(initWidth, initHeight); origin = initOrigin; } Rectangle(int initWidth, int initHeight) { width = initWidth; height = initHeight; origin = new Point(0,0); id = ++numberOfRectangles; System.out.println("Initialized object id in constructor, id:" + id); } // static method for initializing static variable. static int initNumberOfRectangles() { System.out.println("initialize numberOfRectangles in static method"); return 0; } //static initialization block static { System.out.println("initialize numberOfRectangles in static block"); numberOfRectangles = 0; } //non-static initialization block { id = 100; System.out.println("initialize objectId in block, id: " + id); } //final method final int initializeId() { int _id = 200; System.out.println("initialize objectId in final method, id: " + _id ); return _id; } int getID() { return id; } static int getNumberOfRectangles() { return numberOfRectangles; } void setWidth(int newWidth ) { width = newWidth; } int getWidth() { return width; } void setHeight(int newHeight ) { height = newHeight; } int getHeight() { return height; } void setOrigin(Point newOrigin) { origin = newOrigin; } Point getOrigin() { return origin; } int getArea() { return width * height; } String description(String objName) { return "["+objName+"] (id: "+ id +") Width: " + width + ", Height: " + height; } public static void main(String []args) { System.out.println("-------------------------------"); Point p = new Point(10,20); Rectangle rectOne = new Rectangle(30,40, p); System.out.println("-------------------------------"); System.out.println(rectOne.description("rectOne")); System.out.println("Number of Rectangles: " + getNumberOfRectangles() ); } }