ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
char x = 'A';
int i = 0;
System.out.print(true ? 1 : 2.0);
System.out.print(" ");
System.out.print(true ? x : i);
  1. A. 1.0 A
  2. B. 1 A
  3. C. 1.0 65
  4. D. 1 65

Correct answer: C. 1.0 65

The two branches of ?: are brought to one type. int and double give double, so 1 prints as 1.0. char and an int variable give int, so 'A' prints as 65 (only an int constant that fits in char would keep the type char).

More OOP with C++ and Java questions

Exams that ask this topic