Knowee
Questions
Features
Study Tools

If the line:friend class A;appears in class B, and the line:friend class B;appears in class C, then:a.Class A is a friend of class C.b.Class A can access private variables of class B.c.Class C can call class A’s private member functions.d.Class B can access class A’s private variables.

Question

If the line:friend class A;appears in class B, and the line:friend class B;appears in class C, then:a.Class A is a friend of class C.b.Class A can access private variables of class B.c.Class C can call class A’s private member functions.d.Class B can access class A’s private variables.

🧐 Not the exact question you are looking for?Go ask a question

Solution

a. False. The friend declaration in C++ is not transitive. Just because class A is a friend of class B and class B is a friend of class C, it does not mean that class A is a friend of class C.

b. True. In C++, if a class is declared as a friend of another class, it can access the private and protected members of that class. So, class A can access private variables of class B.

c. False. Friendship in C++ is not symmetric. If class B is a friend of class C, it does not mean that class C is a friend of class B. Therefore, class C cannot call class A’s private member functions unless it is explicitly declared as a friend of class A.

d. True. If class B declares class A as a friend, then class B can access the private variables of class A.

This problem has been solved

Similar Questions

What happens when we declare a function as a friend?Select one:a.We allow the function to have access to the public members of the classb.We allow the function to have access to the private and protected members of the classc.We do not allow the function to have access to the private and protected members of the classd.We allow the function to have access to the protected members but not the private members of the class

Which of the following access specifies is used in a class definition by default?a.Friendb.Privatec.Protectedd.Public

Once an object is declared as a friend, _________________________.

class Person {public: int id_; Person* friends_; int num_friends_;};Außerdem sei folgende Speicherbelegung gegeben:Adresse ... 1  2  3  4  5  6  7  8 9 10 11 12 13 14 15 16 ...Wert ... 7 251111141421505210

What is the output of the following snippet? #include <iostream> using namespace std; class C1 { friend class C2; protected: int y; public: int z; private: int x; public: C1() { x = y = z = 11; } }; class C2 { public: C1 a; C2 () { a.x = 22; }; void foo() { cout << a.x << a.y << a.z; } }; int main() { C2 c; c.foo(); return 0; } 111122 Compilation fails 112211 221111

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.