where defined | scope
(visibility) |
lifetime | initialization | |
instance variables | in class, outside methods | within class
(if private) |
created / deleted
(by garbage collection) with object |
initialized to
default value |
static variables | in class, outside methods | within class
(if private) |
created / deleted with
loading / unloading of class |
initialized to
default value |
local variables | anywhere in method | within block {}
or statement (e.g., for()) |
created / deleted when
block / statement entered / exited |
must be initialized
by programmer |
parameter variables | in method header | within method | created / deleted when method
is entered / exited |
initialized with
copies of parameters |
Note: If two variables
with the same name are in scope one is shadowed.
If you e.g., define a local
variable an instance variable of the same name is shadowed!