- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodOverloadTest.java
More file actions
Latest commit
25 lines (21 loc) · 745 Bytes
/
Copy pathMethodOverloadTest.java
File metadata and controls
25 lines (21 loc) · 745 Bytes
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
packagerandom;
publicclassMethodOverloadTest {
// Method to add two integers
publicintadd(inta, intb) {
returna + b;
}
// Overloaded method to add three integers
publicintadd(inta, intb, intc) {
returna + b + c;
}
// Overloaded method to add two double values
publicdoubleadd(doublea, doubleb) {
returna + b;
}
publicstaticvoidmain(String[] args) {
MethodOverloadTestcalc = newMethodOverloadTest();
System.out.println(calc.add(2, 3)); // Calls the first method
System.out.println(calc.add(2, 3, 4)); // Calls the second method
System.out.println(calc.add(2.5, 3.5)); // Calls the third method
}
}