Multiple choice technology programming languages

What happens when you compare two primitives of different numerical types?

  1. compiler error

  2. smaller type is promoted

  3. must explicitly cast

  4. none of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Java automatically promotes the smaller primitive type to match the larger type during comparison operations. This is part of binary numeric promotion - for example, an int compared to a long is promoted to long, a float compared to a double is promoted to double. This promotion happens automatically without requiring explicit casting from the programmer.