Friday, April 6, 2012

Inheriting Multiple Parent Class

Hello Everyone, This is a short post on how to inherit multiple Parent Class to a Child Class.

So far, we know how to inherit single Parent Class, So Another Important Thing You should know is how to add multiple Parent Class.

Lets check the example:

>>> class parentCar:
              car1 = "I am Car1"
              car2 = "I am Car2"
              car3 = "I am Car3"

>>> class parentBike:
              bike1 = "I am Bike1"
              bike2 = "I am Bike2"
              bike3 = "I am Bike3"

>>> class childTransport(parentCar, parentBike): <--Parent Class Inherited
              car4 = "I am Car4"
              bike4 = "I am Bike4"

>>> transport = childTransport() <--Object Created To use the Child Class
>>> transport.car1
'I am Car1'
>>> transport.car3
'I am Car3'
>>> transport.car4
'I am Car4'
>>> transport.bike1
'I am Bike1'
>>> transport.bike3
'I am Bike3'
>>> transport.bike4
'I am Bike4'

I hope this is pretty much self explanatory, you just need to remember this, as it helps a lot while scripting.

Thank You and Dont Forget to check my Next Post.


Post a Comment