Skip to main content

Friend Functions

1).What is a friend function in C++?

1) A function that can access private and protected members of a class
2) A function declared inside another function
3) A function used for operator overloading
4) None of the above

2).How is a friend function declared?

1) Using the friend keyword
2) Using the public keyword
3) Using the virtual keyword
4) None of the above

3).Can a friend function be a member of a class?

1) No
2) Yes
3) Only in derived classes
4) None of the above

4).Which of the following can be a friend function?

1) A non-member function
2) A member function of another class
3) Both A and B
4) None of the above

5).What is the purpose of a friend function?

1) To provide controlled access to private data
2) To inherit properties from a base class
3) To override virtual functions
4) None of the above

6).Can friend functions be inherited?

1) No
2) Yes
3) Only in certain cases
4) None of the above

7).What is the scope of a friend function?

1) It is not limited to the class
2) It is limited to the class
3) It has global scope
4) None of the above

8).Can a friend function access the members of multiple classes?

1) Yes
2) No
3) Only if those classes are related
4) None of the above

9).Which of the following is true about friend functions?

1) They violate encapsulation
2) They increase security
3) They require virtual inheritance
4) None of the above

10).Can a friend function be overloaded?

1) Yes
2) No
3) Only with operator functions
4) None of the above