Wrapper Classes: Integer and Double

AP Computer Science A· difficulty 4/5

<code>Integer a = 200; Integer b = 200; a == b</code> is

  • A

    Always true

  • B

    Compile error

  • C

    Often false (different Integer objects)

    check_circle
  • D

    Throws NPE

Explanation

For values outside the cache (typically -128 to 127), Integer literals create new objects; <code>==</code> compares references.

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

Related questions