Class inheritance question


If a class (like ElectricCar) inherits from Car, why do I need to add the other self.whatever thats already in Car? why doesnt it inherit those attributes(<-might not be correct word)

`class ElectricCar(Car):`
        def __init__(self, model, color, mpg, battery_type):
            self.model = model     }\
           `self.color = color`    } ---why do i need this stuff in `electricCar`
            `self.mpg   = mpg`     }/
           ` self.battery_type = battery_type`

It just seems like a waste. what if Car had a hundred of those, and if i create another class that inherits all that i have to re-write a hundred attributes?(or whatever they are called)


You're overriding __init__

You can (and usually should) call the super-class's __init__

You wouldn't have a hundred named arguments to a constructor or any other method/function.

If there were a lot of values then you'd use some container for them, like list.

..And your car is electric, so it won't have an mpg.. I guess setting it to 0 would sort of make sense.. not really.. Kind of a design flaw with the Car class