String Objects: Concatenation, Literals, and More

AP Computer Science A· difficulty 4/5

For <code>String a = "hi"; String b = "hi";</code><code>a == b</code> is

  • A

    true (string literal pool optimization)

    check_circle
  • B

    Throws NPE

  • C

    Compile error

  • D

    false (different objects)

Explanation

Java string literals are interned; same literal → same object reference.

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

Related questions