ProgrammingVery hardAccenture · GATE CS

What is printed?

What is printed?
Object o = true ? 1 : 2.0;
System.out.print(o);
  1. A. 1
  2. B. 1.0
  3. C. true
  4. D. Compile error

Correct answer: B. 1.0

The two branches undergo binary numeric promotion to double, so the value is 1.0, not an Integer 1.

More OOP with C++ and Java questions

Exams that ask this topic