package polymorphism;
public class Shapes{
void draw(){}
void erase(){}
}
package polymorphism;
public class Square extends Shapes {
public void draw(){System.out.println("Square.draw");}
public void erase(){System.out.println("Square.erase");}
}
package polymorphism;
public class riangle extends Shapes {
public void draw(){ System.out.println("riangle.draw"); }
public void erase(){ System.out.println("riangle.erase"); }
}
package polymorphism;
public class Circle extends Shapes {
public void draw(){ System.out.println("Circle.draw");}
public void erase(){System.out.println("Circle.erase");}
}
package polymorphism;
import java.util.Random;
public class RandomShapeGenerator {
private Random rand=new Random(47);
public Shapes next(){
switch(rand.nextInt(3)){
default: case 0:return new Circle();
case 1:return new riangle();
case 2:return new Square();
} } }
package polymorphism;
public class Shape {
private static RandomShapeGenerator gen=new RandomShapeGenerator();
public static void main(String args[]){
Shapes []s=new Shapes[9]; for(int i=0;i<s.length;i++)
s[i]=gen.next();
for(Shapes shp:s);
shp.draw();
} }