1class Calculate
2{
3 void sum (int a, int b)
4 {
5 System.out.println("sum is"+(a+b)) ;
6 }
7 void sum (float a, float b)
8 {
9 System.out.println("sum is"+(a+b));
10 }
11 Public static void main (String[] args)
12 {
13 Calculate cal = new Calculate();
14 cal.sum (8,5); //sum(int a, int b) is method is called.
15 cal.sum (4.6f, 3.8f); //sum(float a, float b) is called.
16 }
17}
1//https://www.geeksforgeeks.org/overloading-in-java/
2// Java program to demonstrate working of method
3// overloading in Java.
4
5public class Sum {
6
7 // Overloaded sum(). This sum takes two int parameters
8 public int sum(int x, int y)
9 {
10 return (x + y);
11 }
12
13 // Overloaded sum(). This sum takes three int parameters
14 public int sum(int x, int y, int z)
15 {
16 return (x + y + z);
17 }
18
19 // Overloaded sum(). This sum takes two double parameters
20 public double sum(double x, double y)
21 {
22 return (x + y);
23 }
24
25 // Driver code
26 public static void main(String args[])
27 {
28 Sum s = new Sum();
29 System.out.println(s.sum(10, 20));
30 System.out.println(s.sum(10, 20, 30));
31 System.out.println(s.sum(10.5, 20.5));
32 }
33}