Explain Classification of Java Variables (or) What is Scope of a Variable

Scope  of  the  variable:-

The  area  of  program  from  where  the variable can be accessed  is  known  as  scope  of  the  variable.

Java  allows  variables   to be  declared with  in  any  block. A  block defines  a  scope.Java variables   one actually  classified  in to  three types.

Instance  variables

Class  variables

Local  variables


Instance  variable :-


Instance  variables   are  declared  inside the  class.  Instance  variables  are   created  when  the  objects one  instantiated  and  there fore  they are an located  with the  objects. They  take  different values  for  each  object.


Class variables:-


 Class variables  are  declared inside  the  class. Class variables  are global  to  a class and  belong to the  entire  set  of  objects  that  class  creates. Only  one memory location  are created  for  each  class  variable. The  variables   declared  as  static  are called class  variables.

Local  variables  :-


Variables  declared  and  used  inside  methods   one called  local  variables.   Local variables can  also be declared    inside program  blocks  that are defined  between  an opening brace({) & closing brace (}). These   variable  are  visible  to the  program  only from the beginning  of  its  program  block, to the end  of the  program block. When the  program control  leaves  a block  all the variable in   the block  will be cleared.


Related

Java 6716691153414789125

Post a Comment

emo-but-icon

item