Static Members (Methods, Variables, Static Block and Class)
Static Variable
Static Variable
In JAVA, Variables can be declared with the "static" keyword.
Example: static int x = 0;
When a variable is declared with the keyword "static", its called a class variable. All instances share the same copy of the variable. A class variable can be accessed directly with the class, without the need to create an instance.
So a static variable is common to all the objects and can be accessed without using a particular object.
They belong to the class rather than an object, hence they are also known as class variables.
No comments:
Post a Comment