Object Oriented Programming using C++ Questions and Answers – Static Member Functions

This set of Object Oriented Programming (OOPs) using C++ Multiple Choice Questions & Answers (MCQs) focuses on “Static Member Functions”.

1. Which among the following is correct definition for static member functions?
a) Functions created to allocate constant values to each object
b) Functions made to maintain single copy of member functions for all objects
c) Functions created to define the static members
d) Functions made to manipulate static programs
View Answer

Answer: b
Explanation: The functions which are made common, with respect to definition and data usage, to all the objects. These functions are able to access the static data members of a class.

2. The static member functions __________________
a) Have access to all the members of a class
b) Have access to only constant members of a class
c) Have access to only the static members of a class
d) Have direct access to all other class members also
View Answer

Answer: c
Explanation: The static member functions are common for all the objects. These functions can use only the static members of a class in which those are defined. This is because other members change with respect to each object created.

3. The static member functions ____________________
a) Can be called using class name
b) Can be called using program name
c) Can be called directly
d) Can’t be called outside the function
View Answer

Answer: a
Explanation: The static members can be accessed using class name also. This is because the static members remain common to all the objects. Hence objects are not required.
advertisement
advertisement

4. Which is correct syntax to access the static member functions with class name?
a) className . functionName;
b) className -> functionName;
c) className : functionName;
d) className :: functionName;
View Answer

Answer: d
Explanation: The scope resolution operator must be used to access the static member functions with class name. This indicates that the function belongs to the corresponding class.

5. Which among the following is not applicable for the static member functions?
a) Variable pointers
b) void pointers
c) this pointer
d) Function pointers
View Answer

Answer: c
Explanation: Since the static members are not property of objects, they doesn’t have this pointer. Every time the same member is referred from all the objects, hence use of this pointer is of no use.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Which among the following is true?
a) Static member functions can’t be virtual
b) Static member functions can be virtual
c) Static member functions can be declared virtual if it is pure virtual class
d) Static member functions can be used as virtual in Java
View Answer

Answer: a
Explanation: The static member functions can’t be virtual. This is a restriction on static member functions, since the definition should not change or should not be overridden by any other function of derived class. The static members must remain same for all the objects.

7. The static members are ______________________
a) Created with each new object
b) Created twice in a program
c) Created as many times a class is used
d) Created and initialized only once
View Answer

Answer: d
Explanation: The static members are created only once. Then those members are reused whenever called or invoked. Memory is allocated only once.
advertisement

8. Which among the following is true?
a) Static member functions can be overloaded
b) Static member functions can’t be overloaded
c) Static member functions can be overloaded using derived classes
d) Static member functions are implicitly overloaded
View Answer

Answer: b
Explanation: The static member functions can’t be overloaded because the definition must be the same for all the instances of a class. If an overloaded function have many definitions, none of them can be made static.

9. The static member functions _______________
a) Can’t be declared const
b) Can’t be declared volatile
c) Can’t be declared const or volatile
d) Can’t be declared const, volatile or const volatile
View Answer

Answer: d
Explanation: The static member functions can’t be made const, since any object or class itself should be capable of making changes to the function. And the function must retain all changes common to all the objects.
advertisement

10. Which keyword should be used to declare the static member functions?
a) static
b) stat
c) const
d) common
View Answer

Answer: a
Explanation: The member functions which are to be made static, must be preceded with the keyword static. This indicates the compiler to make the functions common to all the objects. And a new copy is not created with each of the new object.

11. The keyword static is used _______________
a) With declaration inside class and with definition outside the class
b) With declaration inside class and not with definition outside the class
c) With declaration and definition wherever done
d) With each call to the member function
View Answer

Answer: b
Explanation: The keyword is used only inside the class while declaring the static member. Outside the class, only definition with proper syntax is given. There is no need of specifying the keyword static again.

12. Which among the following can’t be used to access the members in any way?
a) Scope resolution
b) Arrow operator
c) Single colon
d) Dot operator
View Answer

Answer: c
Explanation: The single colon can’t be used in any way in order to access the static members of a class. Other symbols can be used according to the code and need.

13. We can use the static member functions and static data member __________________
a) Even if class object is not created
b) Even if class is not defined
c) Even if class doesn’t contain any static member
d) Even if class doesn’t have complete definition
View Answer

Answer: a
Explanation: The static members are property of class as a whole. There is no need of specific objects to call static members. Those can be called directly or with class name.

14. The static data member _________________
a) Can be mutable
b) Can’t be mutable
c) Can’t be integer
d) Can’t be characters
View Answer

Answer: b
Explanation: The static data members can never be mutable. There copies are not made. Since those are common and created only once.

15. If static data member are made inline, ______________
a) Those should be initialized outside the class
b) Those can’t be initialized with the class
c) Those can be initialized within the class
d) Those can’t be used by class members
View Answer

Answer: c
Explanation: Since the members are created once and are common for all the instances, those can be initialized inside the class. Those doesn’t change with each object being created hence can be defined inside the class once for all.

Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming (OOPs) using C++, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.