014-005-008
Difference Between Override and Overload
Medium
Problem Description
Difference Between override and Overload
In this problem, you will create a program that implements method overloading in the Calculator class and method overriding through inheritance in the AdvancedCalculator class, reads values from Scanner, and displays the result of each method call to standard output.
Learning Objective: Understand the difference between method override and overload
Overview
Create a program that implements both overloading within a class and overriding through inheritance, using input values to verify the behavior.
Specifications
- Define add(int, int) method in Calculator class
- Overload with add(double, double) in same class
- AdvancedCalculator extends Calculator and overrides add(int, int) (adds 5 to result)
- Main reads values from standard input and tests all methods
Input Format
Read the following values from standard input, one per line:
- Integer a (first argument for int add)
- Integer b (second argument for int add)
- Double c (first argument for double add)
- Double d (second argument for double add)
- Integer e (first argument for AdvancedCalculator add)
- Integer f (second argument for AdvancedCalculator add)
Output Format
Int add: [result of a+b]
Double add: [result of c+d]
Advanced add: [result of e+f+5]
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