The process of defining methods with same name but with different functionalities is termed method overloading. For example, an overloaded draw() method can be used to draw anything, from a circle to an image. Methods with same name, namely, draw, but with different arguments can be used for all cases.
When a method in an object is called, Java verifies its name and argument type so that the appropriate method definition is executed.
To create an overloaded method, several different method definitions are created in the class with the same name but with different parameter lists (either in number or type of arguments). Java allows method overloading as long as each parameter list for the method in question is unique.
Java differentiates overloaded methods based on the number and type of parameters and not on the return type of the method. A compiler error would occur when two methods with the same name and same parameter list but different return types are created.
Program gives an example of an overloaded method.
int Code, Salary;
void setData(int x, String y)
void setData(int x, String y, int z)
System.out.println("Employee Code : "+Code);
System.out.println("Employee Name : "+Name);
System.out.println("Employee Salaryary : "+Salary);
public static void main(String args)
WorkerDetail WD = new WorkerDetail();
WorkerDetail WD1 = new WorkerDetail();
WorkerDetail WD2 = new WorkerDetail();
WD2.setData(13, "Sunny Dadwal", 5000);