Multiple choice technology programming languages

What results from attempting to compile and run the following code? public class Ternary{ public static void main(String args[]){ int a = 5; System.out.println("Value is - " + ((a < 5) ? 9.9 : 9)); } }

  1. 9.9

  2. 9

  3. 9.0

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Since a = 5, the condition (a < 5) is false, so the ternary operator returns the second operand 9. However, the ternary has operands 9.9 (double) and 9 (int), so the result type is double due to numeric promotion. The integer 9 is promoted to 9.0, and the output is 'Value is - 9.0'. Option C is correct.