I am trying to understand what objects are created when we instantiate the child class in Python, for example:
class Car():
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
class ElectricCar(Car):
def __init__(self, make, model, year):
super().__init__(make, model, year)
my_tesla = ElectricCar('tesla', 'model s', 2016)
When we create the object my_tesla, we instantiate the class ElectricCar by calling the constructor of this class, which in his turn calls the constructor of the parent. How does it happen? Right now I have two guesses:
1) super() is just the reference to the parent class, so we call the constructor of the parent by "super().init(make, model, year)" instantiating our child class. As a result we have just ONE object of our class ElectricCar().
2) super(), calls the constructor of the parent, create the object of the "Car" class, then we call the constructor of this object, by "super().init(make, model, year)". As a result we have TWO objects: one object of the class Car() and one object of the class ElectiricCar, in our case they are the same though.
Which one is correct? If neither then please explain what exactly happens in the:
super().__init__(make, model, year)