Bird
0
0

Identify the error in the following code snippet related to method overloading:

medium📝 Debug Q6 of 15
Java - Polymorphism

Identify the error in the following code snippet related to method overloading:

class Calculator {
    int calculate(int a) { return a * 2; }
    double calculate(int a) { return a / 2.0; }
}
AMethods have different parameter types
BMethods have the same signature differing only by return type
CMethods differ by number of parameters
DNo error, valid overloading
Step-by-Step Solution
Solution:
  1. Step 1: Check method signatures

    Both methods have identical parameter lists (int a).
  2. Step 2: Understand overloading rules

    Overloading requires different parameter lists; return type alone cannot differentiate.
  3. Final Answer:

    Methods have the same signature differing only by return type -> Option B
  4. Quick Check:

    Return type alone doesn't overload methods [OK]
Quick Trick: Overloading requires different parameters, not just return type [OK]
Common Mistakes:
  • Believing return type differentiates overloads
  • Ignoring identical parameter lists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes