Python Programming - Inheritance - Discussion

Discussion Forum : Inheritance - General Questions (Q.No. 102)
102.
Consider the following code:
class Bird:
    def __init__(self, species):
        self.species = species

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

Post your comments here:

Your comments will be displayed after verification.