J.I · Java 25 practice question

A developer combines a long and a float in an arithmetic expression. What does this Java 25 program print?

void main() {
    long count = 10L;
    float factor = 2.5f;
    var result = count + factor;
    System.out.println(((Object) result).getClass().getSimpleName());
}
Choose one answer
Check answer and explanation

Correct answer: Float

Explanation

In a numeric context with a float and a long, the promoted type is float and the long undergoes widening primitive conversion to float, which boxes to Float.

Common trap

Even though long uses 64 bits and float uses 32 bits, numeric promotion still promotes to float rather than long. Promotion only chooses double when at least one operand is already of type double.

Source: JLS SE 25 §5.6. Numeric Contexts
Checked against the cited text on 2026-11-25.

Report an error in this question