Python Programming - Inheritance - Discussion

Discussion Forum : Inheritance - General Questions (Q.No. 87)
87.
Consider the following code:
class Vehicle:
    def __init__(self, brand):
        self.brand = brand

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

Post your comments here:

Your comments will be displayed after verification.