Python Programming - Inheritance - Discussion

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

class Square(Shape):
    def __init__(self, color, side_length):
        super().__init__(color)
        self.side_length = side_length
What is the primary advantage of using super().__init__(color) in the Square class constructor?
To call the constructor of the Square class
To create a new instance of the Shape class
To initialize attributes of the Shape class in the Square class
To access superclass attributes directly
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.