Coupon Accepted Successfully!


static Object

In C, it is common to declare variable static and it gets initialized to zero. The object is a composition of one or more member variables. There is a mechanism called constructor to initialize member variables of the object to desired values. The constructors are explained in the next chapter. The static keyword can be used to initialize all class data member variables to zero. Declaring object itself as static can do this. Thus all its associated members get initialized to zero. The following program illustrates the working of static object.

8.20 Write a program to declare static object. Display its contents.

Explanation: The class bita has two member variables c and k and two member functions plus() and show(). In function main(), the object A is declared. It is also declared as static. The data members of object A are initialized to zero. The function plus() is invoked, which adds 2 to the values of c and k. The function displays values of c and k. Declare object static does not mean that entire class is static including member function. The declaration of static object removes garbage of its data members and initializes them to zero.

Test Your Skills Now!
Take a Quiz now
Reviewer Name