Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 | public class Main { int instance_varialbe = 100; // instance variable static int val = 100;// static variable void getValue() { int local_Variable = 90;// local variable } } |
Variable is a name of memory location that can contain a data value.
A variable has a data type.
There are three types of variables in java: local, instance and static.
Local Variable : A variable which is declared inside the method is called local variable.
Instance Variable : A variable which is declared inside the class but outside the method, is called instance variable .
Static variable : A variable that is declared as static is called static variable. Memory allocation for such variables only happens once when the class is loaded in the memory.