Static members - placement practice test

Static members - placement practice test


1. If a class contains static variable, then every object of the class has its copy of static variable.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False
Explanation: Only one copy of static variable is created for entire class and is shared by all the objects of that class.




2. Default value of static variable is_____

a. 0
b. 1
c. Garbage value
d. Compiler dependent
View Answer / Hide Answer

ANSWER: a. 0




3. Static variable in a class is initialized when

a. every object of the class is created
b. last object of the class is created
c. first object of the class is created
d. No need to initialize static variable
View Answer / Hide Answer

ANSWER: c. first object of the class is created




4. Static variable declared in a class are also called_________

a. instance variable
b. named constant
c. global variable
d. class variable
View Answer / Hide Answer

ANSWER: d. class variable




5. We can initialize a value of static variable of a class only when its object is created. No other initialization is permitted.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False
Explanation: It is not mandatory that static variable must be initialized only after first class object is created. For sake of understanding, refer following code.




6. Which of the following are true about static member function?

1. They can access non-static data members
2. They can call only other static member functions
3. They can access global functions and data
4. They can have this pointer
5. They cannot be declared as const or volatile

a. Only 2
b. Only 2,5
c. Only 2,3,4,5
d. Only 2 , 3 , 5
e. All of these
View Answer / Hide Answer

ANSWER: d. Only 2 , 3 , 5




7. Static variable must be declared in public section of the class.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False



Post your comment