Skip to content
Sharp

Core Java · interview question

What happens when you use a switch statement with an integer variable representing shipping zones to apply specific fees?

Multiple choiceMediumchapter-1-curatedpremiumcore-javaconditions-and-branching
java
int shippingZone = 2;
switch (shippingZone) {
  case 1: applyFee(5); break;
  case 2: applyFee(10); break;
  case 3: applyFee(15); break;
}
Choose one answer
Answer and explanation

Correct answer

B. All cases execute unless a break is used.

Why

Switch statements execute all subsequent cases after a match unless a break is encountered. This behavior allows for 'fall-through' to execute multiple blocks but usually requires breaks to prevent unintended execution.

Test yourself on Core Java

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

Start free test
All Core Java questions →