The following program will illustrates the method overriding concept onf OOP. Here parent and child classes have defined with the same method name and signature. According to context the method would be executed. The actual meaning of overriding means ignoring the parent method when both have same method signature, and executing the derived class method. ===== METHOD OVERRIDING SAMPLE PROGRAM ===== class FirstClass: #define the super class def setdata(self, value): # define methods self.data = value # ‘self’ refers to an instance def display(self): print self.data class SecondClass(FirstClass): # inherits from FirstClass def display(self): # redefines display print 'Current Data = %s' % self.data x=FirstClass() # instance of FirstClass y=SecondClass() # instance of SecondClass x.setdata('Before Method Overloading') y.setdata('After Method Overloading') x.display() y.display() ===== Static and Class Method Sample Prog...
Learn from the learners, learning is forever - Life is short it need Python programming !!!