Comparing Objects

AP Computer Science A· difficulty 4/5

For <code>String a = new String("hi"); String b = new String("hi");</code> — what is <code>a == b</code> and <code>a.equals(b)</code>?

  • A

    == true; equals false

  • B

    Both false

  • C

    Both true

  • D

    == false; equals true

    check_circle

Explanation

<code>==</code> compares references (different objects → false); <code>.equals</code> compares content (same content → true).

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

Related questions