Skip to content
Sharp

Core Java · interview question

Which of the following correctly uses a switch statement to apply a discount based on the product category?

Multiple choiceEasychapter-1-curatedpremiumcore-javaconditions-and-branching
java
String category = "electronics";
switch (category) { case "electronics": applyDiscount(); break; }
Choose one answer
Answer and explanation

Correct answer

D. Switch (category) { case "electronics": applyDiscount(); break; }

Why

In Java, switch statements can use strings, and string literals must be enclosed in double quotes. Each case should end with a break unless intentionally falling through.

Test yourself on Core Java

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

Start free test
All Core Java questions →