Python Constructor Overriding
When the programmer writes a constructor in the sub class, the super class constructor is not available to the sub class . In this case, only the sub class constructor is accessible from the sub class object. That means the sub class constructor is replacing the super class constructor. This is called constructor overriding .
Similarly in the sub class, if we write a method with exactly same name as that of super class method, it will override the super class method. This is called method overriding .
Constructor Overriding Example
class Father:
def __init__(self):
self.property = 800000.00
def display_property(self):
print('Father\'s property=', self.property)
class Son(Father):
def __init__(self):
self.property = 200000.00
def display_property(self):
print('Child\'s property=', self.property)
s = Son()
s.display_property()
In this case, how to call the super class constructor so that we can access the father's property from the Son class? For this purpose, we should call the constructor of the super class from the constructor of the sub class using the super() method.