Examveda

A static data member is given a value

A. within the class definition

B. outside the class definition

C. when the program is executed

D. never

Answer: Option B

Solution (By Examveda Team)

Static data members in C++ are special variables associated with a class, not individual objects of that class.
This means there's only one copy of the static member shared by all objects of the class.
Because of this shared nature, you can't initialize them directly within the class declaration like regular member variables.
Instead, you need to give them a value outside the class definition.
This is done typically by providing an initialization outside the class, often in the same header file or a separate source file.
Therefore, the correct answer is that a static data member is given a value outside the class definition.

Join The Discussion

Comments (1)

  1. Revathi
    Revathi :
    10 months ago

    no- a static member function can be instantiated within a class or outside the class also

Related Questions on Object Oriented Programming Using C Plus Plus

A default catch block catches

A. all thrown objects

B. no thrown objects

C. any thrown object that has not been caught by an earlier catch block

D. all thrown objects that have been caught by an earlier catch block