Skip to content
Sharp

Core Java · interview question

Which of the following methods is most likely violating the single responsibility principle in an e-commerce application?

Multiple choiceHardchapter-1-curatedpremiumcore-javamethods
Choose one answer
Answer and explanation

Correct answer

D. Void applyDiscountAndUpdateInventory(double price, int quantity)

Why

The method applyDiscountAndUpdateInventory is likely violating the single responsibility principle because it appears to perform two distinct operations: applying a discount and updating inventory. Each method should focus on a single task.

Test yourself on Core Java

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

Start free test
All Core Java questions →