Friday, 1 July 2011

What is the Static Member ?


When you declare a member variable as static and when the application starts, the compiler creates a copy of that member. This member would be maintained by the compiler while the program is running. If you declare an instance of a class, the static member is not part of the object: the compiler creates and maintains the static member, whether you use it or not, whether you declare a class variable or not.
When a class has a static member variable, you don't need to declare an instance of that class to access the static member variable. When the application starts, the member variable is automatically available and you can access it when necessary. You can access it either to retrieve its value or to modify it.
Variables and methods marked static belong to the class rather than to any particular instance of the class. These can be used without having any instances of that class at all. Only the class is sufficient to invoke a static method or access a static variable. A static variable is shared by all the instances of that class i.e only one copy of the static variable is maintained.

No comments:

Post a Comment