Examveda

What is the value of the expression 6 > 4 ? 10 : 20 in Java?

A. 6

B. 4

C. 10

D. 20

Answer: Option C

Solution (By Examveda Team)

The expression is 6 > 4 ? 10 : 20

Let'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

This Question Belongs to Java Program >> Operators

Join The Discussion

Comments (1)

  1. Nihal Sathawane
    Nihal Sathawane:
    9 months ago

    This uses ternary operator in java 6 > 4 this is condition and if 6 is greater than 4 then it will print 10 otherwise it will execute second condition that is 20 but here 6 is greater so 10 will print

Related Questions on Operators