Bird
0
0

Identify the error in this method declaration:

medium📝 Debug Q6 of 15
Java - Methods and Code Reusability
Identify the error in this method declaration:
public static int addNumbers(int a, b) {
  return a + b;
}
AMethod must return void
BReturn statement is incorrect
CStatic keyword is not allowed here
DParameter b is missing its type
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter list syntax

    Each parameter must have a type; 'b' lacks a type here.
  2. Step 2: Confirm other parts are correct

    Return type, static keyword, and return statement are valid.
  3. Final Answer:

    Parameter b is missing its type -> Option D
  4. Quick Check:

    Each parameter needs a type [OK]
Quick Trick: Every parameter must have a type declared [OK]
Common Mistakes:
  • Omitting type for second parameter
  • Thinking static is invalid
  • Misplacing return statement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes