polymorphic code example
Example: polymorphic
for(Shape shape : shapes)
if(shape instanceof Circle)
{
Circle c = (Circle) shape; // cast to a circle
c.draw(g); // call the circle's draw method
}
else if(shape instanceof Rect)
{
Rect r = (Rect) shape;
r.draw(g);
}