Which one of the following is correct, when a class grants friend status to…
2016
Which one of the following is correct, when a class grants friend status to another class ?
- A.
The member functions of the class generating friendship can access the members of the friend class.
- B.
All member functions of the class granted friendship have unrestricted access to the members of the class granting the friendship.
- C.
Class friendship is reciprocal to each other.
- D.
There is no such concept.
Attempted by 109 students.
Show answer & explanation
Correct answer: B
Answer: All member functions of the class granted friendship have access to the private and protected members of the class granting the friendship.
What friendship does: Declaring class B as a friend inside class A allows B (and B's member functions) to access A's private and protected members.
What friendship does not do: It does not give A access to B's private members; it is not automatically reciprocal (B must be declared friend by A and vice versa if mutual access is desired).
Other important points: Friendship is not inherited and is not transitive—making B a friend of A does not make C (a friend of B) a friend of A.