Skip to content
Sharp

Core Java · interview question

Identify the logical error in the following statement: boolean freeShipping = (cartTotal > 50) || (hasCoupon = true);?

Multiple choiceHardchapter-1-curatedpremiumcore-javaoperators-and-expressions
java
boolean freeShipping = (cartTotal > 50) || (hasCoupon = true);
Choose one answer
Answer and explanation

Correct answer

C. The assignment should be a comparison.

Why

The logical error is using '=' for assignment instead of '==' for comparison. This leads to unexpected behavior.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →