Wrapper Classes: Integer and Double

AP Computer Science A· difficulty 4/5

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

  • A

    Always true

  • B

    Throws NPE

  • C

    Compile error

  • D

    True due to small-integer caching (-128 to 127)

    check_circle

Explanation

Java caches small Integers; <code>valueOf(5)</code> returns the same cached object.

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

Related questions