Q10
What is the value of the expression 6 > 4 ? 10 : 20 in Java?
A.
6
B.
4
C.
10
AnswerD.
20
Answer: Option C
Solution
Answer: Option C
Solution:
The expression is 6 > 4 ? 10 : 20Let's break it down:
6 > 4 is a comparison. It checks if 6 is greater than 4. This is true.The
? and : are the ternary operator symbols.If the comparison (
6 > 4) is true, the expression evaluates to the value before the colon (:), which is 10.If the comparison were false, it would evaluate to the value after the colon, which is
20.Since
6 > 4 is true, the whole expression simplifies to 10.Therefore, the correct answer is C: 10