J.I · Java 25 practice question

Under what condition does the Java Language Specification consider the binary multiplication operator * to be commutative?

Choose one answer
Check answer and explanation

Correct answer: When the operand expressions have no side effects

Explanation

Multiplication with * is commutative only if the operand expressions have no side effects; otherwise, left-to-right evaluation order can change behavior.

Common trap

Side effects in operand expressions can break commutativity because Java evaluates operands left to right. Commutativity without side effects applies to multiplication generally, not exclusively to integer types.

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

Report an error in this question