CS100A. You HAVE to be able to produce what is written below for the QUIZ IN LECTURE on Tuesday, 27 October 1998 Four kinds of variables: parameter: a variable declared in the parentheses of a method definition. local variables: a variable declared in the body of a method. Field (or instance variable): variable declared in a class (non-static) Static field (or class variable): a variable declared static in a class. Assignment statement: has the form var= expr; To execute an assignment statement: evaluate the expr and store its value in the var. argument: an expression within the parentheses of a method call. To execute a method call: 1. Draw a box (called a frame) for the method call; the fram is drawn at the place where the method name was found. 2. In the frame, put in the parameters and local variables of the method. 3. Assign the arguments of the call to the parameters of the method. 4. Execute the method body. 5. Erase the frame. To evaluate an expression new C(arguments): 1. Draw a new instance of class C --filling in the instance variables and non-static methods. 2. Execute the method call C(arguments) --using the method name C found in the new instance generated in (1). 3. The result of the evaluation is a reference to the new instance. For a class C, at runtime, the system keeps a box for its static fields and methods and for its instances. Here is an example, with two instances, which presumably are refenced by some other variables. public class C { int x; static int y= 0; public C(int z) { int b= z; x= b; y= y+1; } public static int sq(int x) {return x*x;} } box for class C ----------------------------------------- | y__2__ sq (a method) | | | | | | instance of C instance of C | | ____________ ____________ | | | | | | | | | C | | C | | | | | | | | | | x_8__ | | x_25_ | | | | | | | | | |____________| |____________| | | | ----------------------------------------