Saturday, 3 January 2015

Java Variables

Variables are the names of the memory locations that can store values. A variable must be declared before we can store value in it.

Java has three kind of variables:


  • Local variables
  • Instance variables
  • Class variables
Local variables are used inside blocks or methods. Instance variables are used to define attributes or state of an object. Class variables are used to define attributes/state, which is common for all the objects of a class.

All the three types of variables are declared in similar manner but use of class and instance variables differ from the use of local variables. There are also differences in terms of the modifiers (e.g. visibility / access modifiers), which can be used with the variables.

No comments:

Post a Comment