blog

Home / DeveloperSection / Blogs / Method overlaoding in JAVA

Method overlaoding in JAVA

ANkita gupta 2100 29-May-2015

If a class have multiple methods by the same name but different parameters it is known as method overloading.

If we have to perform only one operation, having the same name of the methods increases the readability of the program. Highlighted one is the advantage of the method overloading.

The different way to overload the method:

  • By changing number of arguments
  • by changing the data type
Example of method overloading by changing the number of arguments:
class Calculation
{
    void sum(int a,int b){System.out.println(a+b);
}
void sum(int a,int b,int c)
{
    System.out.println(a+b+c);
}
public static void main(String args[])
{
    Calculation obj=new Calculation();
    obj.sum(10,10,10);
    obj.sum(20,20);
}

Output:

30 

40 


Updated 25-Feb-2018

Leave Comment

Comments

Liked By