Categories of Variables
- Categories of variables
- Instance fields (balance in BankAccount)
- Local variables (newBalance in deposit
method)
- Parameter variables (amount in deposit
method)
- An instance field belongs to an object
- The fields stay alive until no method uses the object any longer
- In Java, the garbage collector periodically reclaims
objects when they are no longer used
- Local and parameter variables belong to a method
- Instance fields are initialized to a default value, but you must
initialize local variables