Bird
0
0

Identify the error in this method declaration:

medium📝 Debug Q14 of 15
Java - Methods and Code Reusability
Identify the error in this method declaration:
public void displayMessage(String message, int) {
  System.out.println(message);
}
AParameter list missing variable name for int type
BMethod must return a value
CCannot use String as parameter type
DSystem.out.println is invalid here
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter list syntax

    Each parameter must have a type and a variable name. Here, int has no name.
  2. Step 2: Identify the error

    Missing variable name after int causes a syntax error.
  3. Final Answer:

    Parameter list missing variable name for int type -> Option A
  4. Quick Check:

    Parameters need type and name [OK]
Quick Trick: Every parameter needs a name after its type [OK]
Common Mistakes:
  • Omitting parameter names
  • Thinking return type is missing
  • Misunderstanding print statement usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes