LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 14

Why are protected data members discouraged? Answer, explanation & discussion

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

Why do many guidelines prefer private data with protected member functions over protected data members?

  • A Protected data is slower
  • B Every derived class – including ones written later – can modify protected data, so the base class cannot guarantee its invariants Correct
  • C Protected data cannot be initialized
  • D Protected data is not inherited
Correct Answer: Option B

Protected functions let derived classes change state only through checked operations.

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