ProgrammingHardProduct-company placement · GATE CS

What is printed?

What is printed?
char c = 'a';
c += 1;
System.out.print(c + 1);
System.out.print(" " + c + 1);
  1. A. c b1
  2. B. 99 c
  3. C. 99 b1
  4. D. b1 b1

Correct answer: C. 99 b1

c += 1 compiles because compound assignment casts back to char, so c is 'b'. c + 1 is int arithmetic, 98 + 1 = 99. In " " + c + 1 the left operand is a String, so concatenation runs left to right: " b" then " b1".

More OOP with C++ and Java questions

Exams that ask this topic