EXPRESSIONS
Conditional Operator
? :
15.24
Each operand of
||
 must be of type
boolean,
 or a compile time error occurs.
The type of a conditional or expression is always
boolean
.
At run time, the left hand operand expression is evaluated first; if its value is
true
, the value of the conditional or expression is
true
 and the right hand oper 
and expression is not evaluated. If the value of the left hand operand is
false
,
then the right hand expression is evaluated and its value becomes the value of the
conditional or expression. Thus,
||
 computes the same result as
|
 on
boolean
operands. It differs only in that the right hand operand expression is evaluated
conditionally rather than always.
15.24   Conditional Operator
? :
The conditional operator
? :
 uses the boolean value of one expression to decide
which of two other expressions should be evaluated.
The conditional operator is syntactically right associative (it groups right to 
left), so that
a?b:c?d:e?f:g
 means the same as
a?b:(c?d:(e?f:g))
.
ConditionalExpression:
ConditionalOrExpression
ConditionalOrExpression
 ?
Expression
 :
ConditionalExpression
The conditional operator has three operand expressions;
?
 appears between
the first and second expressions, and
:
 appears between the second and third
expressions.
The first expression must be of type
boolean
, or a compile time error occurs.
The conditional operator may be used to choose between second and third
operands of numeric type, or second and third operands of type
boolean
, or sec 
ond and third operands that are each of either reference type or the null type. All
other cases result in a compile time error.
Note that it is not permitted for either the second or the third operand expres 
sion to be an invocation of a
void
 method. In fact, it is not permitted for a condi 
tional expression to appear in any context where an invocation of a
void
 method
could appear ( 14.7).
367






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved