Python Programming - Inheritance - Discussion

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

class Cat(Animal):
    def __init__(self, name, species):
        super().__init__(species)
        self.name = name
What is the primary purpose of using super().__init__(species) in the Cat class constructor?
To call the constructor of the Cat class
To create a new instance of the Animal class
To initialize attributes of the Animal class in the Cat class
To access superclass attributes directly
Answer: Option
Explanation:
super().__init__(species) is used to call the constructor of the superclass Animal 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.