Types of variables in java

Types of variables in java

  1. Local
  2. Instance
  3. Class
  4. Reference

 

  1. Local: The variables which are declared and defined inside a block are called local variables as their scope is local to that block and cant accessed from outside of the block.
  2. Instance: The variables which are declared outside a method but inside a class are called instance variables. These variables are encapsulates in the object of the class.
  3. Class variables: variables which are declared or defined outside the method but inside the class and are declared static are called static variable or class variable. These variables get loaded into the memory while loading the class and do not need the object of the class.
  4. Reference variables: The variables which stores the instance of the class i.e. which are used as a reference to show instance are known as reference variables.

e.g.            Hello   ob  =  new  Hello();

Here ob is a reference variable.

Leave a Reply

Your email address will not be published. Required fields are marked *