-
An expression involving byte, int, and literal numbers is promoted to which of these?
-
- int
- long
- byte
- float
- NA
- int
Correct Option: A
A literal integer is always an int, but the result of an expression involving anything int-sized or smaller is always an int. In other words, add two bytes together and you'll get an int—even if those two bytes are tiny. Multiply an int and a short and you'll get an int. Divide a short by a byte and you'll get an int.
So an expression involving bytes, ints, shorts, literal numbers, the entire expression is promoted to int before any calculation is done.
An implicit cast happens when you're doing a widening conversion. In other words, putting a smaller thing (say, a byte) into a bigger container (like an int).