-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverloading.java
More file actions
27 lines (23 loc) · 854 Bytes
/
Overloading.java
File metadata and controls
27 lines (23 loc) · 854 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
26
27
class Calculator {
// Method to add two integers
public int add(int a, int b) {
return a + b;
}
// Overloaded method to add three integers
public int add(int a, int b, int c) {
return a + b + c;
}
// Overloaded method to add two double values
public double add(double a, double b) {
return a + b;
}
}
public class OverloadingExample {
public static void main(String[] args) {
Calculator calc = new Calculator();
// Calling overloaded methods
System.out.println("Sum of two integers: " + calc.add(5, 10)); // Calls add(int, int)
System.out.println("Sum of three integers: " + calc.add(5, 10, 15)); // Calls add(int, int, int)
System.out.println("Sum of two doubles: " + calc.add(5.5, 10.5)); // Calls add(double, double)
}
}