ProgrammingVery hardGATE CS · TCS Digital · Advanced

What is printed?

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

Correct answer: B. 1.0a97

Mixing int and double promotes to double (1.0). A char with an int constant that fits in char stays char ('a'). With a non-constant int variable the result type is int, so 'a' is printed as 97.

More OOP with C++ and Java questions

Exams that ask this topic