Method Overloading

One of the best feature of OOP concepts is polymorphism. Polymorphism means "Single interface Multiple behaviour". Polymorphism can be achieved at compile time and run time. Java allows programmer to write multiple methods with same name. All those methods have different parameters. On the basis of those parameter java attach method call to method body.


Method overloading means defining multiple behaviour with same method name. When multiple methods are defined with same name, only difference is in there arguments (Number of arguments or type of arguments), it is known as method overloading. Return type don't play any role in overloading. In java whenever any method is called, java start a search to find called method



Method overloading by changing number of parameter

Example :

 // file: demo.java 
// www.jgyan.com
class demo
{
void show(int a, int b)
{
System.out.println("method1 a:"+a);
System.out.println("method1 b:"+b);
}
void show(int a)
{
System.out.println("method1 a:"+a);
}
}