Q33.Marks: +2.0UGC NET Paper 2: Computer Science 7th Dec 2023 Shift 2
Given below are two statements:
Statement (I): The friend function and the member functions of a friend class directly access the private and protected data.
Statement (II): The friend function can access the private data through the member functions of the base class
In the light of the above statements, choose the most appropriate answer from the options given below:
1.Both Statement I and Statement II are correct
2.Both Statement I and Statement II are incorrect
3.Statement I is correct but Statement II is incorrect✓ Correct
4.Statement I is incorrect but Statement II is correct
Solution
The correct answer is option 3: Statement I is correct but Statement II is incorrect
Key Points
Friend Function: A friend function in C++ is a function that is not a member of a class but has access to its private and protected members. It is declared using the keyword friend inside the class.
Friend Class: All member functions of a friend class can directly access private and protected members of the class that declared it as a friend.
Statement I: TRUE ✅
The friend function and member functions of a friend class can directly access the private and protected data of the class in which they are declared as friend.
This is by definition of friendship in C++.
Statement II: FALSE ❌
A friend function does not need to go through member functions of the base class to access private members.
It either has direct access (if declared friend), or it doesn’t have access at all.
Also, friend functions are not inherited through base classes — so they don't have privileged access via base class methods unless explicitly declared as friend in that class.
Hence, only Statement I is correct.
Final Answer:Option 3) Statement I is correct but Statement II is incorrect