The scope of a variable bounds the part of the code in which the variable is clear. As a general
rule, variables that are circle enclosed by a block are not provided outside that block. The life
cycle of a variable apply to how long the variable exists before it is overcome.
Overcomeing variables apply to disengage the memory that was advantage to the variables
when said it. We have written a few classes till now. You might have observed that not all
variables are the same. The ones said in the body of a way(method) were different from those
that were said in the class alone. There are three types of variables: instance variables, formal
parameters or local variables and local variables.
Instance variables
Instance variables are those that are circle enclosed by a class alone and not in any
way(method) or creater of the class. They are known as instance variables because every
instance of the class (object) insure a copy of these variables. The scope of instance variables
is confident by the entrance specificize that is useable to these variables. We have already
seen about it shortly.The life cycle of these variables is the same as the life cycle of the object
to which it belongs. Object once produced do not exist for ever. They are overcome by the
junk gatherer of Java when there are no more footnote to that object. We shall see about Java’s
automatic junk gatherer later on.
Argument variables
These are the variables that are circle in the header oaf gatherer or a way(method) . The
scope of these variables is the way(method) or creater in which they are circle. The life cycle
is limited to the time for which the way(method) keeps executing. Once the way(method)
finishes execution, these variables are overcome.
Local variables
A local variable is the one that is said enclosed by a way(method) or a creater (not in the
header). The scope and life cycle are limited to the way(method) alone.
One important distinction between these three types of variables is that entrance specificizes
can be useable to instance variables only and not to argument or local variables.
In addition to the local variables circle in a way(method) , we also have variables that are
circle in bocks life an if block and an else block. The scope and is the same as that of the
block alone.