Bird
0
0

What is the error in this Java code snippet?

medium📝 Debug Q6 of 15
Java - Memory Management Basics
What is the error in this Java code snippet?
public class Example {
  public static void main(String[] args) {
    int y;
    System.out.println(y);
  }
}
AVariable 'y' is used before initialization
BMethod main is missing return type
CClass Example must be declared public
DSystem.out.println syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check variable initialization

    Local variables must be initialized before use.
  2. Step 2: Identify error

    Variable 'y' is declared but not initialized before printing.
  3. Final Answer:

    Variable 'y' is used before initialization -> Option A
  4. Quick Check:

    Local vars need initialization before use [OK]
Quick Trick: Local vars must be initialized before use [OK]
Common Mistakes:
  • Assuming default initialization for local variables
  • Confusing class fields with local variables
  • Ignoring compiler error messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes