Python Programming - Polymorphism - Discussion

Discussion Forum : Polymorphism - General Questions (Q.No. 73)
73.
What is the output of the following Python code?
class Shape:
    def draw(self):
        return "Drawing a shape"

class Circle(Shape):
    def draw(self):
        return "Drawing a circle"

class Square(Shape):
    def draw(self):
        return "Drawing a square"

def display_shape_info(shape):
    return shape.draw()

circle = Circle()
square = Square()

print(display_shape_info(circle))
print(display_shape_info(square))
Drawing a shape\nDrawing a shape
Drawing a circle\nDrawing a square
Drawing a square\nDrawing a circle
Drawing a circle\nDrawing a circle
Answer: Option
Explanation:
The display_shape_info() function calls the draw() method of the given shape, resulting in the specific drawing for each shape.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.