String Objects: Concatenation, Literals, and More

AP Computer Science A· difficulty 4/5

String a = new String("hi");
String b = new String("hi");
System.out.println(a == b);

What is printed?

  • A

    false

    check_circle
  • B

    0

  • C

    true

  • D

    Error

Explanation

The == operator compares references; new creates two distinct String objects, so a and b refer to different objects.

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

Related questions