15.24
Conditional Operator
? :
EXPRESSIONS
The type of a conditional expression is determined as follows:
If the second and third operands have the same type (which may be the null
type), then that is the type of the conditional expression.
Otherwise, if the second and third operands have numeric type, then there are
several cases:
N
If one of the operands is of type
byte
 and the other is of type
short
, then
the type of the conditional expression is
short
.
N
If one of the operands is of type
T
 where
T
 is
byte
,
short
, or
char
, and the
other operand is a constant expression of type
int
 whose value is represent 
able in type
T
, then the type of the conditional expression is
T
.
N
Otherwise, binary numeric promotion ( 5.6.2) is applied to the operand
types, and the type of the conditional expression is the promoted type of the
second and third operands.
If one of the second and third operands is of the null type and the type of the
other is a reference type, then the type of the conditional expression is that
reference type.
If the second and third operands are of different reference types, then it must
be possible to convert one of the types to the other type (call this latter type
T
)
by assignment conversion ( 5.2); the type of the conditional expression is
T
.
It is a compile time error if neither type is assignment compatible with the
other type.
At run time, the first operand expression of the conditional expression is eval 
uated first; its
boolean
 value is then used to choose either the second or the third
operand expression:
If the value of the first operand is
true
, then the second operand expression is
chosen.
If the value of the first operand is
false
, then the third operand expression is
chosen.
The chosen operand expression is then evaluated and the resulting value is con 
verted to the type of the conditional expression as determined by the rules stated
above. The operand expression not chosen is not evaluated for that particular eval 
uation of the conditional expression.
368






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