Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Java - Memory Management Basics
Identify the error in this code snippet:
class Test {
  public static void main(String[] args) {
    Object obj;
    System.out.println(obj);
  }
}
AMissing semicolon after declaration
BObject class cannot be instantiated
CVariable obj is not initialized before use
DSystem.out.println cannot print objects
Step-by-Step Solution
Solution:
  1. Step 1: Check variable initialization

    Variable obj is declared but not assigned any value before printing.
  2. Step 2: Understand Java's requirement for initialization

    Local variables must be initialized before use, otherwise compilation error occurs.
  3. Final Answer:

    Variable obj is not initialized before use -> Option C
  4. Quick Check:

    Uninitialized local variable usage = Compilation error [OK]
Quick Trick: Always initialize local variables before use [OK]
Common Mistakes:
  • Assuming default initialization for local variables
  • Thinking Object class cannot be used directly
  • Ignoring compiler errors on uninitialized variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes