Pages

Monday, 22 February 2016

Hybrid Inheritance

# Write A Program To Show Hybrid Inheritance….
# Set Your Font Type as Courier

class Vehicle :
    def __init__(self,name,model) :
        self.name=name
        self.model=model
    def details(self) :
        print "Name:",self.name,"\n","Model:",self.model
class Car(Vehicle) :
    def __init__(self,name,model,colour) :
        Vehicle.__init__(self,name,model)
        self.colour=colour
    def details(self) :
        Vehicle.details(self)
        print "colour:",self.colour
class Truck(Vehicle) :
    def __init__(self,name,model,hp) :
        Vehicle.__init__(self,name,model)
        self.hp=hp
    def details(self) :
        Vehicle.details(self)
        print "Horse Power:",self.hp
class MonsterTruck(Car,Truck) :
    def__init__(self,name,model,colour,hp,price):
        Car.__init__(self,name,model,colour)
        Truck.__init__(self,name,model,hp)
        self.price=price
        print "Initialized MonsterTruck:",
        print self.name
    def details(self) :
        Car.details(self)
        Truck.details(self)
        print "Price:",self.price
m=MonsterTruck("Mustang",2009,"Blue",900,4200000)

m.details()