Skip to content
Sharp

Object-oriented programming · interview question

What access level should be provided to mutable fields in a class that follows encapsulation principles?

Multiple choiceMediumchapter-3-curatedpremiumoopimmutability-basics
Choose one answer
Answer and explanation

Correct answer

C. Private with public getters and setters.

Why

Mutable fields should be private, with control provided through public getters and setters to encapsulate the data and maintain control over how it is accessed and modified.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →