• Source
    1. class Parent: # define parent class
    2. parentAttr = 100
    3. def __init__(self):
    4. print "Calling parent constructor"
    5.  
    6. def parentMethod(self):
    7. print 'Calling parent method'
    8.  
    9. def setAttr(self, attr):
    10. Parent.parentAttr = attr
    11.  
    12. def getAttr(self):
    13. print "Parent attribute :", Parent.parentAttr
    14.  
    15. class Child(Parent): # define child class
    16. def __init__(self):
    17. print "Calling child constructor"
    18.  
    19. def childMethod(self):
    20. print 'Calling child method'
    21.  
    22. c = Child() # instance of child
    23. c.childMethod() # child calls its method
    24. c.parentMethod() # calls parent's method
    25. c.setAttr(200) # again call parent's method
    26. c.getAttr() # again call parent's method