Variables in Java


  • Variables are named locations in memory that are used to hold a value that may be modified by the program.

  • A variable may take different values at different times during execution.

Syntax for variable declaration :

DataType IdentifierName;

e.g. int a = 20;

Types of Variable :

Local Variable

Instance Variables (Non-Static Fields)

Class Variables (Static Fields)

  1. Local Variable :
    Local variables are those variables whose scope is local to block.A variable which is declared inside the method is called local variable.

  2. Instance Variables (Non-Static Fields)

    A non-static variable which is declared inside the class but out side of the method is instance variable.

    Non-static fields are also known as instance variables because their values are unique to each instance of a class(object), mean to say that every object has its own separate copy of instance variables..

  3. Class Variables (Static Fields)

    A static variable which is declared inside the class is class variable.

    Static variable cannot be local.

Example :

class Test{  
 int x = 50;//instance variable  
 static int y = 100;//static variable  
 void my_Method(){  
  int z = 150;//local variable  

Next topic is Data Types


Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at

Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at

(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017,, All rights reserved