Overriding Methods & Overloading Operators
Overriding Method:
Method overriding is a concept of object oriented programming that allows us to change the implementation of a function in the child class that is defined in the parent class. It is the ability of a child class to change the implementation of any method which is already provided by one of its parent class(ancestors).
Example 1:
Output:
Calling child method
Example 2:
16 is area of square
8 is area of rectangle
Overloading:
In Python you can define a method in such a way that there are multiple ways to call it.
Given a single method or function, we can specify the number of parameters ourself.
Depending on the function definition, it can be called with zero, one, two or more parameters.
This is known as method overloading. Not all programming languages support method overloading, but Python does.
Example 3:
Output:
Hello
Hello Guido
Last updated