|
As soon as the method terminates (i.e., returns), all the local variables defined inside the method are destroyed.
|
(I.e., a local variable is defined between the opening and closing braces of a method)
Example:
public class MyProgram { public static void main(String[] args) { // Body of method "main" double r; // *** Local variable !!! r = MyProgran.min( 1.0, 4.0 ); System.out.println(r); r = MyProgram.min( 3.7, -2.9 ); System.out.println(r); r = MyProgram.min( -9.9, 3.8 ); System.out.println(r); } } |
Next, we study the life time and the scoping rules for local variables