LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 5

Accessing private members of another object Answer, explanation & discussion

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

Can a member function of class Wallet read the private members of a different Wallet object passed to it?

  • A No, only of *this
  • B Yes – access control in C++ is per class, not per object Correct
  • C Only if the other object is const
  • D Only through getters
Correct Answer: Option B

That is how copy constructors and comparison operators read the other object's private data.

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