Python Programming - Inheritance - Discussion

Discussion Forum : Inheritance - General Questions (Q.No. 72)
72.
Consider the following code:
class Shape:
    def __init__(self, color):
        self.color = color

class Circle(Shape):
    def __init__(self, radius, color):
        super().__init__(color)
        self.radius = radius
What is the purpose of using super().__init__(color) in the Circle class?
To call the constructor of the Shape class
To create a new instance of the Circle class
To access superclass attributes directly
To define a new constructor for the Circle class
Answer: Option
Explanation:
super().__init__(color) is used to call the constructor of the superclass Shape and initialize the color attribute.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.