Friend function MCQs – C++

1. Where friend keyword placed for friend function?

(A). Function definition

(B). Function declaration

(c). Main function

(D). Both A and C

friend function declaration and definition
friend function declaration and definition

2. What is the syntax of friend function?

(A). class className

 { friend returnType functionName(parameters);};

(B). class className

{returnType friend functionName(parameters);};

(c). class className

{returnType functionName friend (parameters);};

(D). None of these

C++ example with a program with friend function
C++ example with a program with friend function

 

3. Friend function can access which kind of data members?

(A). Private

(B). Protected

(c). Both of these

(D). None of these

Example of Friend function Can access private and protected data members in C++
Example of Friend function Can access private and protected data members in C++

 

4. Global Function can be Friend functions for which of the following class?

(A). Base class

(B). Derived class

(c). Any classes

(D). None of these

5. If class B is declared friend inside class A, then what will happen?

(A). A can access data members of B

(B). B can access data members of A

(c). Both a and B

(D). None of these

Friend Class in CPP

6. A Function can be friend of how many classes at the same time?

(A). 1

(B). 2

(c). Many

(D). 1 or 2

Friend functionality is not restricted to only one class
Friend functionality is not restricted to only one class

7. Which of the following is true about friend function invocation?

(A). Friend function can be invoked using the object

(B). Friend function cannot be invoked using the object

(c). Both of these

(D). None of these

friend function cannot be invoked using the object as it is not in the scope of that class
friend functions cannot be invoked using the object as it is not in the scope of that class

8. Friend functions have objects as___________?

(A). class

(B). arguments

(c). child

(D). Parent

Example of Friend functions having objects as arguments
Example of Friend functions having objects as arguments

OOP MCQs 

Programming C Plus Plus MCQs Homepage

shamil memory table