Program – 3
AIM :- Write a java program to demonstrate
method overloading.
public class MethodOverloading {
// Method 1: Add two integers
public int add(int a, int b) {
return a + b;
}
// Method 2: Add three integers
public int add(int a, int b, int c) {
return a + b + c;
}
// Method 3: Add two double values
public double add(double a, double b) {
return a + b;
}
public static void main(String[] args) {
MethodOverloading obj = new
MethodOverloading();
// Changed inputs to match new output
[Link]("Addition of two integers: " +
[Link](20, 25)); // 45
[Link]("Addition of three integers: " +
[Link](20, 25, 30)); // 75
[Link]("Addition of two double values: "
+ [Link](4.4, 5.5)); // 9.9
}
}