Method overriding happens if the sub class method satisfies the below conditions with the Super class method:
The key benefit of overriding is that the Sub class can provide some specific information about that sub class type than the super class.
Example:
public class Manipulation{ //Super class public void add(){ } } public class Addition extends Manipulation{ public void add(){ } public static void main(String args[]){ Manipulation addition = new Addition(); //Polymorphism is applied addition.add(); // It calls the Sub class add() method } }
addition.add() method calls the add() method in the Sub class and not the parent class. So it overrides the Super class method and is known as Method Overriding.
We covered nearly 50 + primary Java interview questions in this tutorial for fresh and experienced candidates. Q.1- What is… Read More