ProgrammingModerateAmazon/Microsoft SDE MCQ · Java placement

What is printed?

What is printed?
char c = 'a';
c += 1;
System.out.print(('a' + 1) + "" + (char) ('a' + 1) + c);
  1. A. bbb
  2. B. 98bb
  3. C. 98b98
  4. D. b98b

Correct answer: B. 98bb

'a' + 1 is int arithmetic, giving 98. Casting it back gives 'b', and the compound assignment c += 1 includes an implicit cast to char, so c is 'b' too.

More OOP with C++ and Java questions

Exams that ask this topic