#!/usr/bin/python
class Parent(object): # 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 Child(Parent): # define child class
def __init__(self):
print "Calling child constructor"
def childMethod(self):
print 'Calling child method'
c = Child() # instance of child
I have called created an instance of the Child class here.It doesn't seem to call the constructor of the parent class.The output looks like shown below.
Calling child constructor
In C++ for example when you call the constructor of a derived class the base class constructor get called first.Why is this not happening in Python?