What is meant by Method Overriding?

Method overriding happens if the sub class method satisfies the below conditions with the Super class method:

  • Method name should be same
  • Argument should be same
  • Return type also should be same

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.

Top 50+ Java Interview Questions with Answers

We covered nearly 50 + primary Java interview questions in this tutorial for fresh and experienced candidates.  Q.1- What is… Read More

5 years ago