Method overloading in java

What is Method Overloading:-

In Java, two or more methods may have the same name if they differ in parameters (different number of parameters, different types of parameters, or both). These methods are called overloaded methods and this feature is called method overloading.

Example program:

class Event    // Class name
{
public static void main(String[] args)
{
Event org=new Event();     // org - Create a object  
org.welcome("Ramesh");
org.welcome("Kumar");
org.welcome("Raj");
org.welcome("Ravi","bala","sudha");
}
void welcome(String name)         // Method definition
{
System.out.println("Welcome " +name);
System.out.println("Please come"); 
} 
void welcome(String name1, String name2, String name3)
{
	System.out.println("welcome All " + name1+ name2+name3);
	System.out.println("Please come");
}

}

Output:

javac Event.java //Compile
java Event        //Run
Welcome Ramesh
Please come
Welcome Kumar
Please come
Welcome Raj
Please come
welcome All Ravibalasudha
Please come

Leave a Comment