ProgrammingHardTCS NQT Digital · Accenture Advanced

What is printed?

What is printed?
int i = 0;
System.out.print(true ? 'a' : 0);
System.out.print(true ? 'a' : i);
  1. A. aa
  2. B. 9797
  3. C. a97
  4. D. 97a

Correct answer: C. a97

A constant int that fits in char keeps the type char (a); with a non-constant int operand the conditional is promoted to int (97).

More OOP with C++ and Java questions

Exams that ask this topic