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: 
Ternary operator has return type that is defined before the calculation of the value.
So, if the operator can return both float and int, then the both values are upcasted to the float.
Your answer is casted in this way:

```
(int)9 -> (int)9 -> (float)9.

```

Other situation: If you add float and int, you get float

```
int a = 2;
float b = 4.3f;
float c = a + b;

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