Java programming language types of variables


Instance Variables (Non-Static Fields)

Ø Technically speaking, objects store their individual states in "non-static fields", that is, fields declared without the static keyword.

Ø Non-static fields are also known as instance variables because their values are unique to each instance of a class  


Class Variables (Static Fields) 

Ø class variable is any field declared with the static modifier, this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated


Local Variables 

Ø Similar to how an object stores its state in fields, a method will often store its temporary state in local variables.

Ø The syntax for declaring a local variable is similar to declaring a field (for example, int c= 0;). There is no special keyword designating a variable as local; that determination comes entirely from the location in which the variable is declared — which is between the opening and closing braces of a method.

Ø As such, local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.

Parameters 
Ø The signature for the main method is public static void main(String[] args). Here, the args variable is the parameter to this method. The important thing to remember is that parameters are always classified as "variables" not "fields". 

Comments