What's the benefit i get if i use Method Overriding ?
The derived class or sub class can have its own business logic in it..
Say for example, considering a real time example..
Let us say we have a class where some features of bank transactions are
defined..
Now, we want to write our own bank transactions using already existing
methods defined in the class but extending its behaviiour and with some
modifications...
this is the sitaution where we inherit the class and overrride the
methods which are required to suit our business requirement...
method overriding will be used to redefine the base class methods
functionality in child classes... so base class and child clas method
have different functioality.... It will work differently depends on the
object used to call that one...
Consider the following code in which situation is that, a base class method Area() returns square of a parameter and suppose we want to extend this method in the derived class sothat this square may just be multiplied by a constant pi(3.142) so that it can return area of a circle: