What is polymorphism?
for shape in [Circle(2), Square(3)]:
print(shape.area())Options
- A class that has many attributes and many methods inside
- The same call works on different types, each running its own code (Correct option)
- Changing the type of a variable while the program runs
- Copying one method into many classes of the same program
Answer
The same call (shape.area()) works on different types, each running its own version
Why
Polymorphism means 'many forms': different classes offer the same method name, and the caller does not need to know which class it has.
The loop calls area() on each shape; Circle and Square each compute it their own way.
This removes long if/elif chains that check the type.
Remember
Same method name, different behavior per class.