Skip to content
Sharp

Core Java · interview question

In an e-commerce application, what is a safe way to handle a price field in a Product class?

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

Correct answer

C. Make the price field private and provide a getter method.

Why

Making the price field private and providing a getter ensures controlled access to the field, preventing unauthorized modification.

Test yourself on Core Java

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

Start free test
All Core Java questions →