Header Ads Widget

WAP to show function overloading in java

  Code:-

class calculate
{
public void sum(int a,int b)
{
System.out.println("Sum of "+a+" and "+b+" is "+(a+b));
}
public void sum(int a,int b,int c)
{
System.out.println("Sum of "+a+" , "+b+" and "+c+" is "+(a+b+c));
}
}
class overloading
{
public static void main(String[] args)
{
calculate obj= new calculate();
obj.sum(10,5);
obj.sum(10,2,5);
}
}

Output:-

Sum of 10 and 5 is 15
Sum of 10 , 2 and 5 is 17

Recommended Post:

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments