Scope and Access

AP Computer Science A· difficulty 4/5

<code>if (x > 0) { int y = 10; } System.out.println(y); </code></pre>

  • A

    Prints 10

  • B

    Prints 0

  • C

    Compile error: y out of scope

    check_circle
  • D

    Prints undefined

Explanation

<code>y</code> declared in the if block scope; not visible outside.

Want 10 more like this — adaptive to your weak spots?

Related questions