Multiple choice technology

public class NumbPlay { int x=5; public static void main(String[] args) { new NumbPlay().doPlay(); } void doPlay() { int x; System.out.println(++x); } } The output is

  1. 5

  2. 6

  3. Compile error

  4. Runtime error

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Local variables in Java must be initialized before use. The doPlay() method declares int x but doesn't initialize it before using ++x. This is a compile-time error, unlike instance variables which receive default values. The ++x operator attempts to read x's current value before incrementing, but x has no value.