Python Programming - Classes - Discussion

Discussion Forum : Classes - General Questions (Q.No. 29)
29.
Consider the following Python code:
class Fruit:
    def __init__(self, color):
        self.color = color

class Apple(Fruit):
    def __init__(self, color, variety):
        super().__init__(color)
        self.variety = variety
What is the purpose of `super().__init__(color)` in the `Apple` class?
It initializes the color attribute of the Apple class.
It defines the constructor for the Apple class.
It creates an instance of the Fruit class.
It calls the constructor of the superclass to set the color attribute.
Answer: Option
Explanation:
`super().__init__(color)` is used to call the constructor of the superclass (`Fruit` class) to initialize the `color` attribute of the `Apple` class.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.