Use app×
QUIZARD
QUIZARD
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
431 views
in Programming by (95.6k points)
closed by

In 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:


1. Only I
2. Only II
3. Both I and II
4. Neither I Nor II

1 Answer

0 votes
by (98.6k points)
selected by
 
Best answer
Correct Answer - Option 1 : Only I

Friend 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

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.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...