Bird
0
0

Find the error in this method declaration:

medium📝 Debug Q14 of 15
Java - Methods and Code Reusability
Find the error in this method declaration:
public void printMessage {
  System.out.println("Hello");
}
AMissing parentheses after method name
BMissing return type
CMissing semicolon after println
DMethod name is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check method declaration syntax

    Methods must have parentheses after the name, even if no parameters are used.
  2. Step 2: Identify the missing part

    The code misses parentheses after printMessage, causing a syntax error.
  3. Final Answer:

    Missing parentheses after method name -> Option A
  4. Quick Check:

    Method() needs parentheses [OK]
Quick Trick: Always add () after method name [OK]
Common Mistakes:
  • Forgetting parentheses in method declaration
  • Thinking semicolon needed after method header
  • Assuming method name can have spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes