010-002-008
Method Overload: Type-Based Dispatch
Medium
Problem Description
method Overload: Type-Based Dispatch
In this problem, you will create a program that defines overloaded process methods for int and String types—returning double the value for integers and the string length for strings—and displays the results to standard output.
Learning Objective: Understand and implement method overloading based on argument types
Overview
Define multiple methods with the same name but different argument types. Implement a process method that returns "double the value" for integers and "length" for strings.
Specifications
- process method (int argument): Returns double the value
- process method (String argument): Returns string length
- The appropriate method is automatically selected based on the argument type
Input Format
integer value
string
Output Format
Result (int): [double the integer]
Result (String): [string length]
Input/Output Example
Input:
10
Hello
Output:
Result (int): 20
Result (String): 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