×

Html & Html5

The World's best Software Development Study Portal

Overloading

Overloading in java same type of name but there parameters different type number of parameters ,different type of parameter,or both).This method is called of method overload and this feature called method overloading.

Example

public class Sum{

public int sum(int x, int y) // Overloaded two sum type int parameters

{

return(x+y);

}

public int sum(int x,int y,int z) //Overloaded three sum type int parameters

{

return(x+y+z);

}

public double sum(double x,double y) //Overloaded two double type parameters

{

return(x+y);

}//Driver code

public static void main(String args[])

{

Sum s=new Sum();

System.out.println(s.sum(10,29));

System.out.println(s.sum(45,32,25));

System.out.println(s.sum(15.2,61.2));

}

};

Output: