ArrayList<MyShape> shapes = new ArrayList<MyShape>();
...
MyShape shape;
for (int i = 0; i < 10; i++)
{
shape = generateRandomShape(); // randomly returns a MyCircle or a MySquare
shapes.add(shape);
}
...
public void paint(Graphics g)
{
for (MyShape shape:shapes)
{
shape.paint(g);
}
}