String Objects: Concatenation, Literals, and More

AP Computer Science A· difficulty 3/5

String s = "Sum: " + 2 + 3;
System.out.println(s);

What is printed?

  • A

    Sum: 5

  • B

    Sum: 2 3

  • C

    Sum: 23

    check_circle
  • D

    Sum: 2+3

Explanation

Evaluation is left-to-right; "Sum: " + 2 yields "Sum: 2", then concatenating 3 gives "Sum: 23".

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

Related questions