Saturday 5 December 2015

Python: Multiple inheritance

A class can inherit properties, methods from more than one class.


MultipleInheritance.py

class A:
 def printA(self):
  print("I am in A")
  
class B:
 def printB(self):
  print("I am in B")
  
class C:
 def printC(self):
  print("I am in C")
  
class D(A, B, C):
 def printD(self):
  print("I am in D")
  
obj=D()
obj.printA()
obj.printB()
obj.printC()
obj.printD()


$ python3 MultipleInheritance.py 
I am in A
I am in B
I am in C
I am in D



Previous                                                 Next                                                 Home

No comments:

Post a Comment