1.

If class B inherits class A privately. And class B has a friend function. Will the friend function be able to access the private member of class A?(a) Yes, because friend function can access all the members(b) Yes, because friend function is of class B(c) No, because friend function can only access private members of friend class(d) No, because friend function can access private member of class A alsoI had been asked this question by my school principal while I was bunking the class.I want to ask this question from Access Specifiers topic in division Access Specifiers of Object Oriented Programming

Answer» RIGHT answer is (C) No, because friend function can only access private members of friend class

The explanation: The friend function of class B will not be able to access private members of class A. SINCE B is inheriting class A PRIVATELY, the members will BECOME private in class B. But private members of class A won’t be inherited at all. Hence it won’t be accessible.


Discussion

No Comment Found

Related InterviewSolutions