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. prints: Value is - 9

  2. prints: Value is - 5

  3. Compilation error

  4. None of these


Correct Option: D

AI Explanation

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. The code snippet will not print "Value is - 9" because the condition a &lt; 5 evaluates to false.

Option B) prints: Value is - 5 - This option is incorrect. The code snippet will not print "Value is - 5" because the condition a &lt; 5 evaluates to false.

Option C) Compilation error - This option is incorrect. The code snippet does not contain any syntax errors and will compile successfully.

Option D) None of these - This option is correct. The code snippet will print "Value is - 9" because the condition a &lt; 5 evaluates to false, and the value 9 is returned as the result of the ternary operator. The result is then concatenated with the string "Value is - " and printed to the console.

The correct answer is D. None of these.

Find more quizzes: