Stack frames and objects (like the Idea Lab activity): Correct Solution


Given the code below, this method call:

Wiri.pedim();

...will eventually reach the point marked HERE. Draw a diagram of the stack and the heap at that point.

(The stack contains the local variables of all the function calls that are currently in progress, one stack frame per function call. The heap contains all of the objects that currently exist.)

In your diagram:

The code:

public class Wiri {
    private int edvu;

    Wiri(int edvu) {
        this.edvu = edvu;
    }

    public static void pedim() {
        Wiri es = new Wiri(380);
        new Lerm(660).hontun(47, new Lerm(147));
    }
}
public class Lerm {
    private int istu;
    private Wiri nes;

    Lerm(int istu) {
        this.istu = istu;
    }

    public void setNes(Wiri nes) {
        this.nes = nes;
    }

    public void hontun(int pe, Lerm iss) {
        iss.fengse(iss);
        HERE;
    }

    public void fengse(Lerm ja) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: