Multiple choice technology embedded technologies

What is the output for the following lines of code? 1: System.out.println(" " +2 + 3); 2: System.out.println(2 + 3); 3: System.out.println(2 + 3 +""); 4: System.out.println(2 + "" +3);

  1. A) Compilation error at line 3

  2. B) Prints 23, 5, 5 and 23.

  3. C) Prints 5, 5, 5 and 23.

  4. D) Prints 23, 5, 23 and 23.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Line 1 performs string concatenation, yielding " 23". Line 2 adds integers, outputting 5. Line 3 adds integers first (5) then appends a string, outputting "5". Line 4 concatenates 2, an empty string, and 3, outputting "23".