When nesting method calls, like with
calls are invoked from the outside in:
a() is invoked, then
b() is invoked.
Nested method calls are invoked outside in
Nested method calls are invoked inside out
CorrectionHere is what's right.
The correct way to execute nested method calls is inside out.
For example, when evaluating the expression
b() is called, producing a value,
a() is called, receiving the return value of
b() as an argument.
The corresponding expression tree looks as follows.
b() is called, returning a value of type
a() is called with this value as an argument.
Note that for this composition of the two methods to work,
the return type of
b() needs to be compatible
with the parameter type of
The fact that the call
a() needs the return value of
b() as an argument
b() has to be called before
and thus that these calls evaluate from the inside out.
SymptomsHow do you know your students might have this misconception?
This misconception occurred quite regularly, even for strong students. Here are two diagnostic probes to detect it.
Ask students to draw a tree for the expression
Students with this misconception may draw the following incorrect tree,
where the inner piece of the expression—
is drawn as the root:
Ask student to produce a call trace for code including the following statement:
Students with this misconception may produce the following incorrect trace:
CALL compute RETURN compute CALL eval RETURN eval CALL eval RETURN eval