Method Overloading in Java with Program

In java, it is possible to create methods that have same name, but different parameter lists and different definitions that is called Method Overloading. It is used when objects are required to perform similar tasks but using different input parameters.

Example :

class House
{
 int length, width;
House(int x, int y)     // creating constructor 1
{
 length=x;
 width=y;
}
House(int x)           // creating constructor 2
{
length=width=x;
}
int area()
{
return(length*width);
}
public static void main(String arg[])
{
 House h1=new House(); 
 System.out.println(h1.House(20,16));
 House h2=new House();
 System.out.println(h2.House(20));
}
}

Output :
320
20