class GenericShape { void draw() { System.out.println( this + "Generic Draw"); } void erase() { System.out.println(this + "Generic Erace"); } } class Circle2 extends GenericShape { public String toString() { return "Circle "; } void draw() { System.out.println("Circle Draw"); } void erase() { System.out.println("Circle Erase"); } } class Square2 extends GenericShape { public String toString() { return "Square "; } void erase() { System.out.println("Square Erase"); } } class Triangle2 extends GenericShape { public String toString() { return "Triangle "; } void draw() { System.out.println("Triangle Draw"); } } public class Shapes2 { public static GenericShape randShape() { switch((int)(Math.random() * 3)) { default: case 0: return new Circle2(); case 1: return new Square2(); case 2: return new Triangle2(); } } public static void main(String[] args) { GenericShape[] s = new GenericShape[4]; // Fill up the array with shapes: for(int i = 0; i < s.length; i++) s[i] = randShape(); // Make polymorphic method calls: for(int i = 0; i < s.length; i++){ s[i].draw(); s[i].erase(); } } } ///:~