Test Series - oops

Test Number 49/78

Q: How many types of member functions are possible in general?
A. 2
B. 3
C. 4
D. 5
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: How can static member function can be accessed directly in main() function?
A. Dot operator
B. Colon
C. Scope resolution operator
D. Arrow operator
Solution: 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.
Q: 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();
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: 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(){}
Solution: 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.
Q: Which keyword is used to make a nonmember function as friend function of a class?
A. friendly
B. new
C. friend
D. connect
Solution: 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.

You Have Score    /10