ProgrammingModerateWipro · Capgemini pattern

What is printed?

What is printed?
System.out.print('a' + 1);
System.out.print(" ");
System.out.print("" + 'a' + 1);
  1. A. 98 a1
  2. B. a1 a1
  3. C. b a1
  4. D. 98 98

Correct answer: A. 98 a1

'a' + 1 is char + int, which is numeric addition: 97 + 1 = 98. In "" + 'a' + 1 the left operand is already a String, so each + concatenates: "a" then "a1".

More OOP with C++ and Java questions

Exams that ask this topic