Types of Variables in Java

variable in java


Variables can be classified into different types in Java.

1. Local Variables

2. Instance Variables

3. Static Variables


1. What is a Local Variable in Java ?

A local variable in Java is a variable that is defined within a block or method or constructor. The scope of the local variable is limited only upto that block.

Literally, the variable is local to the block in which it is declared.


2. What is a Instance variable in Java ?

A instance variable are non-static variables. These variables are declared outside any method, constructor or block. 

Instance variables are 

3. What is a static variable in Java ?


A static variable in Java is a variable that is linked to a class. The statica variable is defined by using a static keyword before the variable type.

                for example.    static int num;

In the above example static is keyword, int is datatypte and num is dataname or variable name.

Static variable are special because they have only one copy for the class in which it is defined, regardless of the number of the program execution in over.

They can be accessed by calling with the class name. 

                                ClassName.VariableName





Post a Comment

0 Comments