The following code is a question in the interview book:
[Java]
Int a = 5;
System. out. println ("a =" + (a <5 )? 10.9: 9 ));
The code output is 9.0. Because the three-object operator has a 10.9 value, java will automatically convert the type based on the precision type of the operator. So 9 will change to 9.0
[Java]
Char x = 'X ';
Int I = 10;
System. out. println (false? I: x );
System. out. println (false? 100: x );
The output of this Code is
120
X
For the first row of output, x is upgraded to the int type, which is the same as the previous example.
For the second row, 10 is a constant. If one of the two expressions in the three orders operator is a constant expression and the other is a type T expression, and the constant expression can be expressed by T, the output result is of the T type. Therefore, the output is a character x.
[Java]
System. out. println (true? 100: x );
Therefore, this line of code will output the char value of d, that is, 100.