Skip to content
Sharp

Core Java · interview question

In an e-commerce system, a 'Product' class has a method 'setPrice(double price)'. What could be a potential issue with this setter method?

Multiple choiceMediumchapter-3-curatedpremiumcore-javacode-reading-and-state-safety
Choose one answer
Answer and explanation

Correct answer

C. It may allow setting invalid prices like negative values.

Why

Without proper validation, setter methods like 'setPrice' can allow invalid values (e.g., negative prices) which can lead to incorrect application state and business logic errors.

Test yourself on Core Java

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

Start free test
All Core Java questions →