Inheritance


#1

class Car(object):
condition = "new"
def init(self, model, color, mpg):
self.model = model
self.color = color
self.mpg = mpg
def display_car(self):
print "This is a %s %s with %s MPG."%(self.color,self.model,self.mpg)
def drive_car(self):
self.condition="used"
class ElectricCar(Car):
super(ElectricCar, self).init(model, color, mpg)

my_car= Car("toyota","blue",80)
my_car = ElectricCar("molten salt")


#2

What is your question?


#3

what have i done wrong?
what i need to change/add? and why..


#4

your ElectricCar should have init method to initialize all instance variable (super() + self.battery_type)


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.