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))
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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers