To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) prints: Value is - 9 - This option is incorrect because the code will not print "Value is - 9". Instead, it will print "Value is - 9.0" because the expression (a < 5) ? 9.9 : 9
evaluates to 9.9, which is a double value.
Option B) prints: Value is - 5 - This option is incorrect because the code will not print "Value is - 5". The value of the variable a
is 5, but the ternary expression (a < 5) ? 9.9 : 9
evaluates to 9.9, not 5.
Option C) Compilation error - This option is incorrect because the code will compile successfully without any errors. The code uses valid Java syntax.
Option D) None of these - This option is correct because the code will print "Value is - 9.0". The ternary expression (a < 5) ? 9.9 : 9
evaluates to 9.9, which is a double value. The output will include the decimal point and ".0" because it is a double value.
Therefore, the correct answer is D) None of these.