Site icon Narayana Tutorial

Conditional Operator

The only ternary operator available in java is conditional operator.

int a = ( 10<20 ) ? 30 : 40 ;

System.out.println( a) ; // 30

Nesting of conditional operator is also allowed in java.

(a<b) if it is not compile tie compression than it check for type, not values directly  assigned value ( 30, 40 ) of types.

 final int a = 10 ; b = 20 ; 
byte c = ( a<b ) ? 30 : 40 ;
System.out.println (c) ; // 30