010-001-013
Overload Concept: Calculator Class
Medium
Problem Description
Method Overloading Concept: Calculator Class
In this problem: You will define three add() methods with different parameters (add(int,int), add(double,double), add(int,int,int)) in a Calculator class to demonstrate how the compiler selects the correct method based on arguments.
Learning Objective: Understand method overloading and learn how the compiler resolves method calls by argument types
Overview
Define three add() methods in the Calculator class:
add(int a, int b): Returns the sum of two integersadd(double a, double b): Returns the sum of two doublesadd(int a, int b, int c): Returns the sum of three integers
Specifications
- Each method returns the calculated result (return types: int, double, int respectively)
- In
Mainclass, call each method and display results - Double results display in Java's default format
Output Format
add(3, 5) = 8
add(2.5, 3.7) = 6.2
add(1, 2, 3) = 6
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up