154k views
5 votes
Friend functions can access What kinds of data members

A) Only public members
B) Only private members
C) Only protected members
D) All members

User Fahad Abid
by
9.4k points

1 Answer

6 votes

Final answer:

Friend functions in object-oriented programming, specifically in C++, can access all data members of a class, including private, protected, and public members. Hence, the correct option is D) All members.

Step-by-step explanation:

The question 'Friend functions can access what kinds of data members?' concerns the concept of friend functions within the scope of object-oriented programming, specifically in C++. A friend function is a function that is not a member of a class but has the right to access all data members (private, protected, and public) of that class. Therefore, the correct answer to the question is D) All members.

For example, if we have a class 'Box' with private attributes 'width' and 'height', declaring a function 'displayBoxInfo' as a friend of the class allows this function to access these private members directly, which would not be possible for regular non-member functions.

User Alex Wulff
by
8.3k points

No related questions found