CS111 Prelab 8 Answers

Although you were only asked to draw an invocation tree /box-and-pointer diagram for the prelab, the execution of addProd(L3) can be explained in detail by the Java Execution Model, so it is included here.

Below is a diagram showing all the execution frames created during the execution of addProd(L3), as well as all the list nodes manipulated during this execution. Pointers leading from variables in Execution Land to list nodes in Object Land have been replaced by circled letters that make the diagram look less messy. In many spots, rather than replacing an expression by its value, we have instead shown the resulting value above or below the boxed expression; this makes it easier to see which expressions evaluated to which values. Note that all list nodes are in Object Land because each list node is an object.

It is possible to summarize the above JEM diagram by the invocation tree diagram shown below. Each node of the invocation tree abbreviates one frame of the execution model. Such a node shows: (1) the name of the invoked method; (2) the arguments of the invoked method; and (3) the result of the invoked method. Note that the invocation tree sits in Execution Land and the list nodes still sit in Object Land.