Multiple choice technology architecture

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

The local variable x in doPlay() is declared but never initialized before being used in the expression ++x. Java requires local variables to be initialized before use. The instance variable int x=5 is shadowed by the local int x declaration, so the class field is not relevant here.