// Simple.java -- illustrate simple overriding of methods class Point { protected float x,y; Point (float x, float y) { this.x=x; this.y=y; } @Override public String toString () { return String.format ("(%.2f,%.2f)", x, y); } } class Rectangle extends Point { protected float height, width; Rectangle (float x, float y, float h, float w) { super (x,y); height=h; width=w; } @Override public String toString () { return String.format ("(%.2f,%.2f;h=%.2f,w=%.2f)", x, y, height, width); } } class Circle extends Point { protected float radius; Circle (float x, float y, float r) { super (x,y); radius=r; } @Override public String toString () { return String.format ("(%.2f,%.2f;r=%.2f)", x, y, radius); } } class Simple { public static void main (String [] args) { final Point p = new Point (2.3f, 4.5f); final Rectangle r = new Rectangle (2.3f, 4.5f, 45.1f, 89.1f); final Circle c = new Circle (2.3f, 4.5f, 0.3f); final Point [] list = new Point [] {p, r, c}; for (Point q: list) System.out.println (q.toString()); for (Point q: list) System.out.println (q); // same effect } }