The both parent and child classes, are named my_car
when I print my_car.display_car()
the child class gets printed
the console print this
This is a Silver Tesla with 80 MPG.
The question is why was this printed not the parent class and how can i print the parent class?
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, str(self.mpg)) def drive_car(self): self.condition = "used" my_car = Car("DeLorean", "silver", 88) class ElectricCar(Car): def __init__(self, model, color, mpg, battery_type): super(ElectricCar, self).__init__(model, color, mpg) self.battery_type = battery_type my_car = ElectricCar("Tesla", "Silver", 80, "molten salt") print my_car.display_car()