Variables are named locations in memory that are used to hold a value that may be modified by the program.
A variable may take different values at different times during execution.
DataType Identifier = value (optional);
Example :
int a;
int x = 100;
float f = 2.3f;
etc...
Local Variable
Instance Variables (Non-Static Fields)
Class Variables (Static Fields)
Local Variable :
Local variables are those variables whose scope is local to block.A variable which is declared inside the method is called local variable.
A non-static variable which is declared inside the class but out side of the method is instance variable.
Non-static fields are also known as instance variables because their values are unique to each instance of a class(object),
mean to say that every object has its own separate copy of instance variables..
A static variable which is declared inside the class is class variable.
Static variable cannot be local.
Example :
public class Test{
int x = 50;//instance variable
static int y = 100;//static variable
void myMethod(){
int z = 150;//local variable
}
}