Bird
0
0

Which of the following is a correct method overloading example in Java?

easy📝 Syntax Q12 of 15
Java - Methods and Code Reusability

Which of the following is a correct method overloading example in Java?

class Test {
  void show(int a) {}
  void show(int a, int b) {}
  void show(int a) {}
}
AThis code compiles without errors
BDuplicate method show(int a) causes a compile error
CMethod names must be different to overload
DReturn types must differ for overloading
Step-by-Step Solution
Solution:
  1. Step 1: Check method signatures

    Two methods have the same name and same parameter list: show(int a).
  2. Step 2: Understand overloading rules

    Overloading requires different parameter lists; duplicate signatures cause errors.
  3. Final Answer:

    Duplicate method show(int a) causes a compile error -> Option B
  4. Quick Check:

    Same parameters = error, not overloading [OK]
Quick Trick: Parameters must differ; identical signatures cause errors [OK]
Common Mistakes:
  • Assuming return type difference overloads method
  • Ignoring duplicate parameter lists
  • Thinking method names must differ

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes