Question
Download Solution PDFIn context of C++, consider the following statements:
I. Friend function of a class can directly access both private and protected data of the class.
II. Member function of derived class can directly access both private and protected data of the class.
The true statement(s) is / are:
Answer (Detailed Solution Below)
Detailed Solution
Download Solution PDFFriend Function
In C++, a friend function can be given a special grant to access private and protected members.
Member function of derived class cannot be directly access both private and protected data of the class.
Therefore only 1st statement is correct
Important Points
1) Friends should be used only for limited purpose. too many functions or external classes are declared as friends of a class with protected or private data, it lessens the value of encapsulation of separate classes in object-oriented programming.
2) Friendship is not mutual. If class A is a friend of B, then B doesn’t become a friend of A automatically.
3) Friendship is not inherited
4) The concept of friends is not there in Java.
Last updated on Jun 6, 2025
-> The HTET TGT Applciation Portal will reopen on 1st June 2025 and close on 5th June 2025.
-> HTET Exam Date is out. HTET TGT Exam will be conducted on 26th and 27th July 2025
-> Candidates with a bachelor's degree and B.Ed. or equivalent qualification can apply for this recruitment.
-> The validity duration of certificates pertaining to passing Haryana TET has been extended for a lifetime.
-> Enhance your exam preparation with the HTET Previous Year Papers.