String Objects: Concatenation, Literals, and More

AP Computer Science A· difficulty 4/5

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

What is printed?

  • A

    Sum: 5

    check_circle
  • B

    Sum: 23

  • C

    Sum: 2+3

  • D

    Sum: 2 3

Explanation

Parentheses force 2 + 3 to be evaluated as integer addition first, giving 5, then concatenated to "Sum: ".

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

Related questions