< Java Tutorial

Java variables

← Previous Next →


Variable is name of reserved area allocated in memory. In other words, it is a name of memory location. It is a combination of "vary + able" that means its value can be changed.

Types of Variable

 There are three types of variables in java:

  1. local variable
  2. instance variable
  3. static variable.

Local Variable

A variable which is declared inside the class method(or function) is called local variable.

Instance Variable

A variable which is declared inside the class but outside the method, is called instance variable. It is not declared as static.

Static variable

A variable that is declared as static is called static variable. It cannot be local.

Example to understand variables in java

class A
{  
   int data=50;//instance variable  
   static int m=100;//static variable  
   
   void method() 
   {  
     int n=90;//local variable  
   }  
}//end of class
← Previous Next →