Skip to content
Sharp

Object-oriented programming · interview question

Why can generating getters and setters for every field in a class become a problem in production code?

Multiple choiceMediumchapter-3-curatedpremiumoopgetters-and-setters-design
Choose one answer
Answer and explanation

Correct answer

D. Increases API surface area unnecessarily.

Why

Automatically generating getters and setters for every field can expose internal state unnecessarily, potentially leading to violation of encapsulation and making the class harder to maintain.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →