0% found this document useful (0 votes)
98 views

C++ Friend Function Quiz - Quizizz

Uploaded by

akshaysain940
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

C++ Friend Function Quiz - Quizizz

Uploaded by

akshaysain940
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Worksheets Name

C++ Friend Function Quiz


Class
Total questions: 10
Worksheet time: 5mins
Date
Instructor name: MARY T

 Multiple Choice

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

a) A friend function in C++ is a function b) A friend function in C++ is a function


that can only be called from within that has access to the private and
the class. protected members of a class.
c) A friend function in C++ is a function d) A friend function in C++ is a function
that can only access the public that can be called from any other
members of a class. class except the one it is declared in.

 Multiple Choice

2. What is the syntax of a friend function in C++?

a) friend function_name; b) friend return_type


function_name(parameters);
c) friend function_name(parameters); d) friend return_type function_name;

 Multiple Choice

3. How can a friend function access private members of a class in C++?

a) By using the 'protected' access b) By being declared as a friend inside


specifier the class
c) By using the 'public' access specifier d) By using the 'static' keyword
 Multiple Choice

4. Can a friend function be a member of a class hierarchy in C++?

a) No b) Yes
c) Only in certain cases d) Sometimes

 Multiple Choice

5. What is the difference between a friend function and a member function in C++?

a) A friend function can only access b) A friend function is not a member of


public members of a class, while a a class, while a member function is a
member function can access both member of a class.
public and private members.
c) A friend function can be called d) A friend function is declared inside a
without an object, while a member class, while a member function is
function can only be called using an declared outside the class.
object.

 Multiple Choice

6. True or False: A friend function can access protected members of a class in C++.

a) Only if the friend function is a b) True


member of the class
c) Only if the friend function is declared d) False
in the same file as the class

 Multiple Choice

7. True or False: A friend function can be declared in the private section of a class in
C++.

a) Only in public section b) False


c) True d) Only in derived classes
 Multiple Choice

8. True or False: A friend function can be called using the dot operator in C++.

a) True b) Depends on the compiler


c) Only in certain cases d) False

 Multiple Choice

9. True or False: A friend function can be overloaded in C++.

a) False b) Not sure


c) True d) Maybe

 Multiple Choice

10. True or False: A friend function can be inherited in C++.

a) Depends on the access specifier b) Only in certain cases


c) True d) False
Answer Keys

1. b) A friend function in 2. b) friend return_type 3. b) By being declared


C++ is a function function_name(parameters);as a friend inside
that has access to the class
the private and
protected members
of a class.

4. b) Yes 5. b) A friend function is 6. b) True


not a member of a
class, while a
member function is
a member of a
class.

7. b) False 8. d) False 9. c) True

10. d) False

You might also like