Method Overriding in Java
Method Overriding in Java
If subclass (child class) has the same method as declared in the parent class, it is known as method
overriding in Java.
In other words, If a subclass provides the specific implementation of the method that has been declared
by one of its parent class, it is known as method overriding.
Let's understand the problem that we may face in the program if we don't use method overriding.
Output:
Vehicle is running
Problem is that I have to provide a specific implementation of run() method in subclass that is why we use
method overriding.
Output:
Java method overriding is mostly used in Runtime Polymorphism which we will learn in next pages.
Output:
SBI Rate of Interest: 8
ICICI Rate of Interest: 7
AXIS Rate of Interest: 9