Kinds of variables in Java and its use.

  • Java has three kinds of variables namely,the instance variable,the local variable and the class variable.
  • Local variables are used inside blocks as counters or in methods as temporary variables and are used to store information needed by a single method.
  • Instance variables are used to define attributes or the state of a particular object and are used to store information needed by multiple methods in the objects.
  • Class variables are global to a class and to all instances of the class and are useful for communicating between different objects of all the same class or keeping track of global states.
Posted on by