|
When a program is run (executed), the instructions and variables must be stored in the computer memory (so the CPU can access (= used) them !!!)
|
|
|
As prequisite to the discussion of program organization, I will now review the "life time" of these things
Therefore:
|
|
public class ExampleClass { static int x; // Keyword static defines a Class variable int y; // Absent of static defines an Instance var public int Method1( int a ) // a is a parameter variable { int b; // Local variables are defined inside a method .... } } |
|
|
|
|
|
|
Explanation:
|
The memory contains only:
|
The system heap and system stack are both empty.
x = new BankAccount( .... ); |
the new operation will allocate (= reserve) memory in the program heap for all the instance variables in the (BankAccount) object:
Note:
|
x = Math.sin( 3.14 ); |
The method invocation will allocate (= reserve memory) the parameter variables and the local variables of the method on the program stack:
|
In other words:
|
|
|
|