Skip to content
Sharp

Object-oriented programming · interview question

How would you explain an invariant in object design in an interview?

Multiple choiceHardchapter-3-curatedpremiumoopinvariants-and-validation
Choose one answer
Answer and explanation

Correct answer

A. A rule that should always remain true for a valid object

Why

Invariants define what valid state means. Constructors and mutation methods should protect those rules so the object cannot drift into nonsense business data.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →