| |
Variables are locations in memory in which values can be stored.
Each one has a name, a type, and a value.
Before we can use a variable, we have to declare it. After it is declared, we
can then assign values to it.
|
| |
| Java actually has three kinds of variables: |
| 1. instance variables, |
| 2. class variables, |
| 3. And local variables. |
| |
|
Instance variables, are used to define the attributes of a particular object.
Class variables are similar to instance variables, except
their values apply to all that class's instances (and to
the class itself) rather than having different values for each object.
Local variables are declared and used inside method definitions,
Although all three kinds of variables are declared in much the same ways, class
and instance variables are accessed and assigned in slightly
different ways from local variables.
Java does not have global variables-that is, variables that are global
to all parts of a program. Instance and class variables can be used
to communicate global information between and among objects. |
|