Java-Variable Types

Variable Types

Java variables are actually classified into three types :

1) Instance Variables
2) Class Variables
3) Local Variables

Instance Variables

Instance variables are declared inside a class. Instance variables are created when the objects are instantiated and therefore they are associated with the objects. They take different values for each object.

Class Variables

A static variable is defined for a class itself. Its value does not vary from object to object. There will be only one copy of a static variable and all objects of the class will share it. Due to this reason, static variables are known as class variables.

Local Variables

Variables declared and used inside methods are called local variables. They are called so because they are not available for use outside the method definition. Local variables can also be declared inside program blocks that are defined between an opening brace { and a closing brace }. These variables are visible to the program only from the beginning of its program block to the end of the program block.

Leave a Comment