Well done!
You have completed Advanced Concepts in Object-Oriented Programming: Overriding, Inheritance, and Polymorphism Quiz!
Quiz Question 1 of 5
In a polymorphic context, consider the following code snippet:
`class Shape: def area(self): return "Calculating area"
class Circle(Shape): def area(self): return "Calculating area of a circle"
class Square(Shape): def area(self): return "Calculating area of a square"
shapes = [Circle(), Square(), Shape()] result = [shape.area() for shape in shapes]`
Which of the following statements is true regarding the result of this list comprehension?
Choose the correct answer below:
-
A
The output list will contain
["Calculating area of a circle", "Calculating area of a square", "Calculating area"]
based on the type of each object. -
B
The list comprehension will return
None
for each object because thearea()
method does not return any value. -
C
The output list will contain
["Calculating area", "Calculating area", "Calculating area"]
as polymorphism does not apply here. -
D
The list comprehension will raise an error because
Shape
does not have a concrete implementation ofarea()
.