ProgrammingModerateTCS NQT · Infosys pattern

What is printed?

What is printed?
System.out.print(1 + 2 + "3" + 4 + 5);
  1. A. 3345
  2. B. 339
  3. C. 15
  4. D. 12345

Correct answer: A. 3345

+ groups left to right: 1 + 2 = 3 (numbers), then 3 + "3" = "33" (a String), and from then on every + concatenates: "334", "3345".

More OOP with C++ and Java questions

Exams that ask this topic