Method overloading happens for different classes or within the same class.
For method overloading, subclass method should satisfy the below conditions with the Super class method (or) methods in the same class itself:
Example:
public class Manipulation{ //Super class public void add(String name){ //String parameter } } public class Addition extends Manipulation(){ public void add(){ //No Parameter } public void add(int a){ //integer parameter } public static void main(String args[]){ Addition addition = new Addition(); addition.add(); } }
Here the add() method having different parameters in the Addition class is overloaded in the same class as well as with the super class.
Note: Polymorphism is not applicable for method overloading.
We covered nearly 50 + primary Java interview questions in this tutorial for fresh and experienced candidates. Q.1- What is… Read More