Rohit Gupta
What are the Types of Variables in Java?
By Rohit Gupta in Java on Sep 10 2019
  • Vijay Kumari
    Sep, 2019 16

    In Java, There are three types of variabes, These are:

    1) Local Variable
    A variable, which is declared inside any methods, constructors, and blocks is known as a local variable.
    Its scope is limited because it is used locally in the method. It is created after the creation of the method,
    constructor, block, a local variable is not visible to class and not accessed by the class.

    2) Static Variable
    A static variable is a very important type of variable. We use static keyword with the variable. Hence, it’s called as a static variable.
    Static Variable is declared inside the class and outside the method, constructor and a block. Static variable belongs to the class, not an Object and it is stored in static memory. Its default
    value is 0 and we can call the static variable with its class name.

    3) Instance Variable

    An instance variable is declared inside the class but outside the method, constructor or block. It has the widest scope because it is globally visible to the whole class. It is created at the time of
    object creation. When instance variable is created at that time, it takes space in the heap memory and it is called through the object and the default value is 0.

    For a detailed tutorial and example program on Variables in Java, Visit

    • 1

Most Popular Job Functions