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


Given the code below, this method call:

Mec.siff();

...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 Mec {
    private int pid;

    Mec(int pid) {
        this.pid = pid;
    }

    public static void siff() {
        Dutri de = new Dutri(593);
        Mec hasm = new Mec(522);
        de.setQi(hasm);
        Mec.nacish(new Dutri(313));
    }

    public static void nacish(Dutri tral) {
        HERE;
        Dutri.ronna();
    }
}
public class Dutri {
    private int keSeng;
    private Mec qi;

    Dutri(int keSeng) {
        this.keSeng = keSeng;
    }

    public void setQi(Mec qi) {
        this.qi = qi;
    }

    public static void ronna() {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: