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

When comparing primitives of different numeric types, Java applies binary numeric promotion - the smaller type is automatically promoted (widened) to the larger type. For example, comparing int and long promotes the int to long. No explicit cast is needed.