Skip to content
Sharp

Object-oriented programming · interview question

Why should a Product class in an e-commerce application have private fields?

Multiple choiceEasychapter-3-curatedpremiumoopobject-responsibility
Choose one answer
Answer and explanation

Correct answer

A. To encapsulate data and control access

Why

Private fields in a Product class help encapsulate data and control access through methods, ensuring that any changes to the data are validated and consistent with business rules.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →