What are the different ways of overriding function call in derived class of python? Illustrate with example.

4 views

1 Answers

Overriding enables the programmer to provide specific implementation to a method in the derived class. So, the method invoked depends on the object used to invoke it. If the base class object is used then base class version of the method is called else the derived class method is called, class Parent:

def func(self):

print ‘Parent method’ class child:

def func(self):

print ‘child method’

C = child()

c.func() # child calls overridden method

4 views