0% found this document useful (0 votes)
4 views3 pages

MethodOverloading Final Practical

The document presents a Java program that demonstrates method overloading by defining three 'add' methods with different parameters. It includes methods for adding two integers, three integers, and two double values. The main method creates an instance of the class and prints the results of the addition operations.

Uploaded by

ramramup75
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

MethodOverloading Final Practical

The document presents a Java program that demonstrates method overloading by defining three 'add' methods with different parameters. It includes methods for adding two integers, three integers, and two double values. The main method creates an instance of the class and prints the results of the addition operations.

Uploaded by

ramramup75
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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
}
}

You might also like