Pages

Monday, 22 February 2016

Multiple Inheritance

# Write A Program To Show Multiple Inheritance….
# Set Your font type as Courier
class SpecialEngine(object) :
    def __init__(self,p) :
        self.power=p
    def ignition(self) :
        print "Engine Started"
class Car(object) :
    def __init__(self,clr,seats) :
        self.colour=clr
        self.seatingCapacity=seats
    def changeGears(self,gr) :
        print "Changed to Gear",gr
    def turn(self,direction) :
        print "Turned to",direction,"direction"
class RacingCar(SpecialEngine,Car) :
    def __init__(self,clr,seats,p,tr,spd) :
        SpecialEngine.__init__(self,p)
        Car.__init__(self,clr,seats)
        self.turnRadius=tr
        self.speed=spd
        print "Racing Car instance created"
    def start(self) :
        self.ignition()
        self.changeGears(2)
        print """Racing Car Starts - Ready to vroom!"""
rcar=RacingCar("Blue",2,750,6,200)
rcar.start()

rcar.turn("left")