<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
Code correct but do’n understand what this line is : Car.__init__(self,model,color,mpg)
<What do you expect to happen instead?>
@mtf im sorry, i just have (or had) the same problem, i know that is necessary to add the Car.__init__(self,model,color,mpg) but i still dont quite get it (i´ve read some stuff but i still got some doubts), like why is that necessary?.
for example, i thought that by calling just
def __init__(self, battery_type)```
the ```ElectricCar``` would inherit all the parameters from ```Car``` and it would'nt be necessary to write those again, but it seems that not only we need to do that, but also we have to "call" the class as a function within out child class:
```class ElectricCar(Car):
def __init__(self,model,color,mpg,battery_type):
Car.__init__(self,model,color,mpg)
self.battery_type = battery_type```
forgive the format of the previous code, i dont know how to
anyways, those are my questions, i apreciate any help :slight_smile:
when you define a new init() in derived class, it is necessary to call into that class the init method of its superclass bc you have overridden it.
if you define a NewClass(Superclass) w/o defining init(), Superclass.init(args) remains the default init for the NewClass, and calling the Superclass.init(args) is not necessary if you want the args. of the init method to be requisites for instances you create.
maybe something that will help clarify:
if one wanted to create a NewClass(SuperClass) but not want to have to define all parameters required by the init method of the Superclass for each instance of NewClass, one would override these parameters by redefining init.
They are both the same in one regard, but super() is much more robust when it comes to multiple inheritence. Recommend chase down some reading on this topic, My explanation likely does no justice, by comparison.