Skip to content
Sharp

Core Java · interview question

Consider a boolean 'isAvailable' and a double 'userBalance'. How would you structure an if-else to ensure an item can be purchased if in stock and funds are sufficient?

Multiple choiceMediumchapter-1-curatedpremiumcore-javaconditions-and-branching
Choose one answer
Answer and explanation

Correct answer

B. If (isAvailable && userBalance >= itemPrice) {}

Why

The '&&' operator is used to ensure both conditions—item availability and sufficient user balance—are true before proceeding.

Test yourself on Core Java

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

Start free test
All Core Java questions →