#!/usr/bin/python class Parent: # define parent class parentAttr = 100 def __init__(self): print "Calling parent constructor" def parentMethod(self): print 'Calling parent method' def setAttr(self, attr): Parent.parentAttr = attr def getAttr(self): print "Parent attribute :", Parent.parentAttr class Parent2: parentAttr = 300 def parentMethod(self): print "Calling parent2 method" def setAttr(self, attr): Parent2.parentAttr = attr def getAttr(self): print Parent2.parentAttr class Child(Parent,Parent2): # define child class def __init__(self): print "Calling child constructor" def childMethod(self): print 'Calling child method' c = Child() # instance of child c.childMethod() # child calls its method c.parentMethod() # calls parent's method #c.setAttr(200) # again call parent's method c.getAttr() # again call parent's method
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more