here you can find examples of overrides in java
What is meant by Method Overriding?
Answer: Method overriding happens if the sub-class method satisfies the below conditions with the Super-class method:
- Method name should be the same
- The argument should be the same
- Return type should also be the 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(); //Polimorphism 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.
Overrides example in java: