Skip to content
Sharp

Object-oriented programming · interview question

Consider a 'Product' class in an e-commerce application. What is a potential risk if its price field is public?

Multiple choiceMediumchapter-3-curatedpremiumoopaccess-modifiers-and-visibility
Choose one answer
Answer and explanation

Correct answer

D. The price can be changed without validation.

Why

If the price field is public, it can be accessed and modified directly without any validation. This could lead to incorrect or inconsistent state within the application.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →