250+ TOP MCQs on Static Member Functions and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) 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
Answer: b
Clarification: 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
Answer: c
Clarification: 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
Answer: a
Clarification: 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.

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;
Answer: d
Clarification: 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
Answer: c
Clarification: 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.

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
Answer: a
Clarification: 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
Answer: d
Clarification: The static members are created only once. Then those members are reused whenever called or invoked. Memory is allocated only once.

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
Answer: b
Clarification: 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
Answer: d
Clarification: 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.

10. Which keyword should be used to declare the static member functions?
a) static
b) stat
c) const
d) common
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: c
Clarification: 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
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: c
Clarification: 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.

Leave a Reply

Your email address will not be published. Required fields are marked *