Memory Organization Lifetime and Scope The scope of a variable is the region of a source program in which it can be used. - the scope of a local variable extends from the point of declaration of the variable to the end of the smallest program block enclosing the declaration. This is often the method in which it is declared, but in the inline declaration of a for loop, it is only the for loop. - The scope of an instance variable is the body of the class in which it is declared. For a public/protected variable the scope extends into subclasses. The lifetime of a variable is the time period during the running of the program that the variable exists. (and is accessable). - The lifetime of a local variable is the duration of a call to the method in which the variable is declared. - The lifetime of an instance variable is exactly the same as the lifetime of the variable's object (the object of which the variable is a part). Memory allocation - Space for a local variable (non object) is allocated on the runtime stack. - Since objects in Java are all given space on the heap, instance variables exist on the heap. - Arrays and objects cannot be allocated on the stack because they may persist after the method which created them has exited.