What is a Static Variable in Java ?
Static variable in Java is a variable whose scope is limited to a single class. To declare a variable a static keyword is used.
Use case of static variable :
Suppose you want to declare a variable which is independent of the objects of the class. So you will need to declare a static variable.
What is instance Variable in Java ?
An instance variable is a non-static variable that is declared outside a method, constructor or block.
It is not mandatory to initialize a instance variable. When not initialized the default value of the datatype is assigned to it.
This variables can be accessed by creating objects of the class.
Instance variable need to have a access specifier, if an access specifier is not declared then the default access specifier is assigned.
Instance variable can be accessed by using the '.' symbol.
For example : variableName.ClassName
-min.png)
0 Comments