Java variables are classified into 2 types based on the type of data being stored in it.
- Reference variables (store reference address)
- Primitive data type variables (store data)
Based on their scope, they are classified into 3 types:
- Instance variables — associated with objects and take different values for each Object.
- Class variables — global to a class & belong to all objects of the class. Only one memory location is created for each class variable.
- Local variables — variables declared & used inside methods
- Dynamic initialization of variables is possible in Java. Eg: double c = (a * a + b * b)— (d * d);