The steps in executing a method call
Now that we have shown the format of a frame for a method call, discussed the
call stack of frames, and discussed the communication of argument and result
values, we give the sequence of steps for executing a method call. It is wise to
memorize them and practice doing them on 5-10 small examples..
1. Evaluate the arguments of the call and push them onto the call stack.
2. Draw a frame for the call at the top of the call stack; the frame includes
the argument values at the top of the stack.
2(a) Fill in the name of the method and set the program counter to 1.
2(b) Fill in the scope box with the name of the entity in which the method
appears: the name of a folder for a non-static method or constructor, and
the name of the class for a static method.
2(c) Draw all local variables of the method body in the frame.
2(d) Label the argument values pushed onto the call stack in the first step
with the names of the corresponding parameters.
3. Execute the method body. Whenever a name is referenced, look in the
frame for it. If it is not there, look in the item given by the scope box of
4. Erase the frame —pop it from the stack. If the method is a function and
the call is terminated by execution of a return statement return e; , push
the value of e onto the call stack.
• Method . A method is a recipe for getting something done or producing a result.
There are three kinds of methods in Java: procedure , function , and constructor .
Constructors have to do with initializing objects and are covered fully in Chaps.
3 and 4.
The call stack as a communication device for argument values