+1 vote
in Class 12 by kratos

What are static members of a class? When and how are they useful?

1 Answer

+5 votes
by kratos
 
Best answer

A class can have static data members as well as static member functions.

The static data members are the class variables that are common for all the objects of the class. Only one copy of static data members is maintained which is shared by all the objects of the class. They are visible only within the class but their lifetime is the entire program. They can be accessed by all the member functions. A member function that accesses only static data members of a class is static member functions. It cannot access other data members but static members.

The static data members are useful when some data values are to be shared across objects of the same class.

...