Create a java program that has three version of add method which can add two, three, and four integers.
class Sum_Overloading
{
void add(int x, int y)
{
int sum;
sum = x + y;
System.out.println(" Sum of two integers :" +sum);
}
void add(int x, int y, int z)
{
int sum;
sum = x + y + z;
System.out.println(" Sum of three integers :" +sum);
}
void add(int x, int y, int z, int w)
{
int sum;
sum = x + y + z + w;
System.out.println(" Sum of four integers :" +sum);
}
public static void main(String[] args)
{
Sum_Overloading obj = new Sum_Overloading();
obj.add(10, 15);
obj.add(10, 15, 20);
obj.add(10, 15, 20, 25);
}
}
Output



0 Comments