Python Programming - Classes - Discussion

Discussion Forum : Classes - General Questions (Q.No. 23)
23.
Consider the following Python code:
class Car:
    def __init__(self, brand):
        self.brand = brand

class ElectricCar(Car):
    def __init__(self, brand, battery_capacity):
        super().__init__(brand)
        self.battery_capacity = battery_capacity
What is the purpose of using `super().__init__(brand)` in the `ElectricCar` class?
It initializes the battery capacity.
It calls the constructor of the superclass to set the brand attribute.
It creates an instance of the `Car` class.
It defines the constructor for the `ElectricCar` class.
Answer: Option
Explanation:
`super().__init__(brand)` is used to call the constructor of the superclass (`Car` class) to 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.