Question: I was going through some java interview questions MCQ where I found this code snippet, of which I didn't understand the output, though its only a 2 line code. 

```
int a = 8;
System.out.println(((a<8)? 9.9 : (int)9));

```

Output is 9.0
I didn't understand why it is not 9 ?

Answer: 
Because you are not casting all of them . you are just casting second result to int.

But don't forget first result is float so all of structure must be same type.
You need to cast all of them as same type like int or float.

```
int a = 8;
System.out.println(""+ (int)( (a<8)? 9.9 :  9));

```

output : 

```
9

```
The return type of the ternary operator is determined according to quite complicated rules:
[Java Language Specification](https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.25). Specifically, in your case:

> 
> 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.
> 
> 
> 

So in your case you get return type double.