Method Overloading in Java

Method Overloading : In Java, it is possible to create methods that have the same name, but different parameter lists and different definitions. This is called method overloading. Method overloading is used when objects are required to perform similar tasks but using different input parameters. When we call a method in an object, Java matches up the method name first and then the number and type of parameters to decide which one of the definitions to execute. This process is known as polymorphism.

To create an overloaded method, all we have to do is to provide several different method definitions in the class, all with the same name, but with different parameter lists.

e.g. /* An example of constructor overloading*/
class Room
{
float len;
float wid;
Room (float a, float b)
{
len=a;
wid=b;
}
Room(float x)
{
len=wid=x;
}
int area()
{
return (len*wid);
}
}
Author:- Kritika Saxena