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


Given the code below, this method call:

Iss.dadod();

...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 Iss {
    private int wel;
    private Cic oid;
    private Iss pril;

    Iss(int wel) {
        this.wel = wel;
    }

    public void setOid(Cic oid) {
        this.oid = oid;
    }

    public void setPril(Iss pril) {
        this.pril = pril;
    }

    public static void dadod() {
        Cic erdi = new Cic(394);
        erdi.setGisa(erdi);
        Cic.ibon(erdi, new Cic(731));
        new Cic(409).larpri(erdi);
    }
}
public class Cic {
    private int prol;
    private Cic gisa;

    Cic(int prol) {
        this.prol = prol;
    }

    public void setGisa(Cic gisa) {
        this.gisa = gisa;
    }

    public void ptoic(int qa) {
        Cic hos = new Cic(272);
        HERE;
        Cic.splai();
    }

    public static void ibon(Cic el, Cic on) {
        on.setGisa(el);
        on.lewu(42, on, new Iss(945));
        new Cic(763).cuass(el, on);
    }

    public void lewu(int cabo, Cic au, Iss iaie) {
        au.ptoic(cabo);
    }

    public void cuass(Cic arre, Cic o) {
    }

    public void larpri(Cic ba) {
        Iss muac = new Iss(534);
    }

    public static void splai() {
        int idco = 76;
        int vont = 53;
        Cic cil = new Cic(460);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: