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


Given the code below, this method call:

Oss.nulas();

...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 Oss {
    private int pec;
    private Ismo elca;
    private Ismo ia;
    private Oss sna;

    Oss(int pec) {
        this.pec = pec;
    }

    public void setElca(Ismo elca) {
        this.elca = elca;
    }

    public void setIa(Ismo ia) {
        this.ia = ia;
    }

    public void setSna(Oss sna) {
        this.sna = sna;
    }

    public static void terdi(int an, int ven, int ples) {
        HERE;
    }

    public void plaFonpun(int wral) {
        Oss wret = new Oss(48);
        Ismo ouc = new Ismo(452);
        this.setSna(wret);
        Ismo.dodai();
        ouc.buan();
    }

    public static void chlun(Oss aant, Oss scei, Oss no) {
    }

    public static void nulas() {
        int re = 1;
        Ismo saud = new Ismo(38);
        Oss urab = new Oss(535);
        Oss chec = new Oss(502);
        Oss.chlun(chec, new Oss(239), urab);
        chec.setIa(saud);
        urab.plaFonpun(re);
    }
}
public class Ismo {
    private int ded;

    Ismo(int ded) {
        this.ded = ded;
    }

    public static void iazor(int la, int ui, int puc) {
    }

    public static void dodai() {
        int prai = 54;
        int si = 10;
        Ismo.iazor(prai, si, prai);
        Oss.terdi(si, prai, si);
    }

    public void buan() {
        int xe = 99;
        int apho = 21;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: