DEVFYI - Developer Resource - FYI

What is the numeric promotion?

Java Interview Questions and Answers (part 1)


(Continued from previous question...)

63. What is the numeric promotion?

Numeric promotion is used with both unary and binary bitwise operators. This means that byte, char, and short values are converted to int values before a bitwise operator is applied.
If a binary bitwise operator has one long operand, the other operand is converted to a long value.
The type of the result of a bitwise operation is the type to which the operands have been promoted. For example:
short a = 5;
byte b = 10;
long c = 15;
The type of the result of (a+b) is int, not short or byte. The type of the result of (a+c) or (b+c) is long.

(Continued on next question...)

Other Interview Questions