LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 3

What is a class invariant? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

What is a class invariant?

  • A A const data member
  • B A condition that holds for every object of the class between member function calls, e.g. "balance ≥ 0" Correct
  • C A variable that never changes type
  • D A static member
Correct Answer: Option B

The constructor establishes it and every public member function preserves it. Private data makes this enforceable.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links