This set of Object Oriented Programming using C++ Problems focuses on “Types of Member Functions”.
1. How many types of member functions are possible in general?
a) 2
b) 3
c) 4
d) 5
View Answer
Explanation: There are basically 5 types of member functions possible. The types include simple, static, const, inline, and friend member functions. Any of these types can be used in a program as per requirements.
2. Simple member functions are ______________________
a) Ones defined simply without any type
b) Ones defined with keyword simple
c) Ones that are implicitly provided
d) Ones which are defined in all the classes
View Answer
Explanation: When there is no type defined for any function and just a simple syntax is used with the return type, function name and parameter list then those are known as simple member functions. This is a general definition of simple members.
3. What are static member functions?
a) Functions which use only static data member but can’t be accessed directly
b) Functions which uses static and other data members
c) Functions which can be accessed outside the class with the data members
d) Functions using only static data and can be accessed directly in main() function
View Answer
Explanation: The static member functions can be accessed directly in the main function. There is no restriction on direct use. We can call them with use of objects also. But the restriction is that the static member functions can only use the static data members of the class.
4. How can static member function can be accessed directly in main() function?
a) Dot operator
b) Colon
c) Scope resolution operator
d) Arrow operator
View Answer
Explanation: The static member functions can be accessed directly in the main() function. The only restriction is that those must use only static data members of the class. These functions are property of class rather than each object.
5. Correct syntax to access the static member functions from the main() function is ______________
a) classObject::functionName();
b) className::functionName();
c) className:classObject:functionName();
d) className.classObject:functionName();
View Answer
Explanation: The syntax in option b must be followed in order to call the static functions directly from the main() function. That is a predefined syntax. Scope resolution helps to spot the correct function in the correct class.
6. What are const member functions?
a) Functions in which none of the data members can be changed in a program
b) Functions in which only static members can be changed
c) Functions which treat all the data members as constant and doesn’t allow changes
d) Functions which can change only the static members
View Answer
Explanation: The const member functions are intended to keep the value of all the data members of a class same and doesn’t allow any changes on them. The data members are treated as constant data and any modification inside the const function is restricted.
7. Which among the following best describes the inline member functions?
a) Functions defined inside the class only
b) Functions with keyword inline only
c) Functions defined outside the class
d) Functions defined inside the class or with the keyword inline
View Answer
Explanation: The functions which are defined with the keyword inline or are defined inside the class are treated to be inline functions. Definitions inside the class are implicitly made inline if none of the complex statements are used in the definition.
8. What are friend member functions (C++)?
a) Member function which can access all the members of a class
b) Member function which can modify any data of a class
c) Member function which doesn’t have access to private members
d) Non-member functions which have access to all the members (including private) of a class
View Answer
Explanation: A non-member function of a class which can access even the private data of a class is a friend function. It is an exception on access to private members outside the class. It is sometimes considered as a member functions since it has all the access that a member function in general have.
9. What is the syntax of a const member function?
a) void fun() const {}
b) void fun() constant {}
c) void const fun() {}
d) const void fun(){}
View Answer
Explanation: The general syntax to be followed in order to declare a const function in a class is as in option a. The syntax may vary in different programming languages.
10. Which keyword is used to make a nonmember function as friend function of a class?
a) friendly
b) new
c) friend
d) connect
View Answer
Explanation: The keyword friend is provided in programming languages to use it whenever a functions is to be made friend of one class or other. The keyword indicates that the function is capable of new functionalities like accessing private members.
11. Member functions _____________________
a) Must be defined inside class body
b) Can be defined inside class body or outside
c) Must be defined outside the class body
d) Can be defined in another class
View Answer
Explanation: The functions definitions can be given inside or outside the body of class. If defined inside, general syntax is used. If defined outside then the class name followed by scope resolution operator and then function name must be given for the definition.
12. All type of member functions can’t be used inside a single class.
a) True
b) False
View Answer
Explanation: There is no restriction on the use of type of member functions inside a single class. Any type any number of times can be defined inside a class. The member functions can be used as required.
13. Which among the following is true?
a) Member functions can never be private
b) Member functions can never be protected
c) Member functions can never be public
d) Member functions can be defined in any access specifier
View Answer
Explanation: The member functions can be defined inside any specifier. There is no restriction. The programmer can apply restrictions on its use by specifying the access specifier with the functions.
14. Which keyword is used to define the static member functions?
a) static
b) stop
c) open
d) state
View Answer
Explanation: The static keyword is used to declare any static member function in a class. The static members become common to each object of the class being created. They share the same values.
15. Which keyword is used to define the inline member function?
a) no keyword required
b) inline
c) inlined
d) line
View Answer
Explanation: The inline keyword is used to defined the inline member functions in a class. The functions are implicitly made inline if defined inside the class body, but only if they doesn’t have any complex statement inside. All functions defined outside the class body must be mentioned with an explicit inline keyword.
Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).
To practice all areas of Object Oriented Programming using C++ Problems, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Apply for C++ Internship
- Practice Information Science MCQs
- Check Object Oriented Programming Books