J.I · Java 25 practice question

A developer refactors (a * b) * c into a * (b * c) where a, b, and c are double variables. Which statement about floating-point multiplication in Java is accurate?

Choose one answer
Check answer and explanation

Correct answer: Floating-point multiplication is not associative

Explanation

Floating-point multiplication is not associative in Java, so regrouping (a * b) * c as a * (b * c) can produce different results.

Common trap

Having the same type guarantees associativity for integer multiplication, not for floating-point multiplication. Even positive finite floating-point numbers can round differently depending on grouping.

Source: JLS SE 25 §15.17.1. Multiplication Operator *
Checked against the cited text on 2026-11-25.

Report an error in this question