-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverloadingAddition.java
More file actions
49 lines (38 loc) · 1.1 KB
/
Copy pathOverloadingAddition.java
File metadata and controls
49 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// package MethodOverloading;
public class OverloadingAddition {
//Overloading based on the datatype
public int add(int a, int b) {
return a + b;
}
public double add(double i, double j) {
return i + j;
}
public String add(String s1, String s2) {
return s1 + s2;
}
//overloading based on the number of parameters
public int add(int a, int b, int c) {
return a + b + c;
}
public int add(int a, int b, int c, int d) {
return a + b + c + d;
}
public double add(double i, double j, double k) {
return i + j + k;
}
public double add(double i, double j, double k, double l) {
return i + j + k + l;
}
public String add(String s1, String s2, String s3) {
return s1 + s2 + s3;
}
//based on the order of parameters
public String add(int age, String name) {
String s = "Age is: " + age + " and name is: " + name;
return s;
}
public String add(String name, int age) {
String s = "Name is: " + name + " and age is: " + age;
return s;
}
}