Bird
0
0

Find the mistake in this Java code snippet:

medium📝 Debug Q6 of 15
Java - Methods and Code Reusability
Find the mistake in this Java code snippet:
public class Example {
  public static void printMessage() {
    System.out.println("Hello World");
  }
  public static void main(String[] args) {
    printMessage;
  }
}
AMethod call missing parentheses
BMethod name is misspelled
CMissing return type in method declaration
DIncorrect use of semicolon after method call
Step-by-Step Solution
Solution:
  1. Step 1: Identify the method call

    The line printMessage; attempts to call the method.
  2. Step 2: Check method call syntax

    In Java, method calls require parentheses even if there are no parameters.
  3. Final Answer:

    Method call missing parentheses -> Option A
  4. Quick Check:

    Method calls must include parentheses [OK]
Quick Trick: Always use parentheses when calling methods [OK]
Common Mistakes:
  • Omitting parentheses when calling a method
  • Confusing method call with variable reference
  • Adding semicolon inside method call parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes