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

In Java, when comparing two different primitive numerical types (such as int and double), binary numeric promotion automatically promotes the operand with the smaller range or precision to match the larger/wider type before the comparison is executed, preventing compile errors.