Variables - Kinds, Scope, Lifetime

Kind of
Variable

Scope
(where it exists)

Lifetime
(when it exists)

Instance - defined outside of any method

Class Scope - all of the class methods can use it

Exists from when the object that contains it is created to when it is destroyed

Static/class - defined outside of any method and tagged with the static keyword

Class Scope - all of the class methods can use it
Methods outside the class can also use public static variables by preceding them with the name of the class and a dot, eg., Math.PI

Exists the whole time the program is running

Local - defined within a method

Block Scope - can only be used within the block of code enclosed in {} where it is defined

Exists while the code within the block is executing