shape5: Rect.java

/*
 * Definition of class Rect
 */

class Rect {

	private int x, y, wid, ht; //*1 Instance variables are private

	public Rect (int xin, int yin, int widin, int htin) { //*2 Constructor
		x = xin; y = yin; //*2
		wid = widin; ht = htin; //*2
	}

	public void draw() {
		System.out.println ("Drawing rectangle at " 
			+ x + ", " + y + ", " + wid + ", " + ht);
	}

	public float area() { //*3 Can still access private vars from inside our methods
		return (float) (wid * ht); //*3
	}
}
[download file]