What does polymorphism buy you?
java
List<Shape> shapes = List.of(new Circle(), new Square());
for (Shape s : shapes) s.draw();
Each shape draws itself correctly, even though the loop only knows about Shape.
What is happening?
java
List<Shape> shapes = List.of(new Circle(), new Square());
for (Shape s : shapes) s.draw();
Each shape draws itself correctly, even though the loop only knows about Shape.
What is happening?