Local
variables
-
Variables declared in the body of a particular method.
-
When a method terminates,
the
values of its local variables are lost.
- An
object has attributes that are carried with the object as it’s used in a
program.
-
An object's attributes exist before
a method is called on an object and
after the method completes execution.
A
class normally consists of one or more methods that manipulate
the attributes
that belong to a particular object of the class.
-
Attributes are represented as variables in a class declaration
-
Called
fields
-
Declared inside a class declaration but outside the bodies of
the class’s method declarations
Instance variable
-
When each object of a class maintains its own copy of an attribute, the field
is an instance variable
-
Each object (instance) of the class has a separate instance of the variable in
memory.