Test Series - oops

Test Number 62/78

Q: 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
Solution: 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.
Q: Which among the following is not applicable for the static member functions?
A. Variable pointers
B. void pointers
C. this pointer
D. Function pointers
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: The static members are created only once. Then those members are reused whenever called or invoked. Memory is allocated only once.
Q: 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
Solution: 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.
Q: The static data member ________________
A. Can be mutable
B. Can’t be mutable
C. Can’t be integer
D. Can’t be characters
Solution: The static data members can never be mutable. There copies are not made. Since those are common and created only once.
Q: 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
Solution: 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.
Q: Which keyword should be used to declare the static member functions?
A. static
B. stat
C. const
D. common
Solution: 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.
Q: 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
Solution: 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.

You Have Score    /10