Answers for "polymorphic"

-2

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);
         }
Posted by: Guest on May-09-2021

Browse Popular Code Answers by Language