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


Given the code below, this method call:

Ilrad.mifal();

...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 Ilrad {
    private int dessu;
    private Ilrad acs;
    private Ilrad oss;

    Ilrad(int dessu) {
        this.dessu = dessu;
    }

    public void setAcs(Ilrad acs) {
        this.acs = acs;
    }

    public void setOss(Ilrad oss) {
        this.oss = oss;
    }

    public static void esaUphash(int ibra, int a, Ilrad aon) {
        int ir = 26;
        int ganu = 26;
        Ilrad.phisa(ir);
        Somir.fesOdgas(ganu, ir);
    }

    public void ongSchop(Somir slil) {
    }

    public static void mifal() {
        Ilrad ou = new Ilrad(330);
        Somir su = new Somir(473);
        ou.setOss(ou);
        new Somir(144).trisfi();
        Ilrad.cuiEpho();
    }

    public static void phisa(int epo) {
        int omi = 57;
        int so = 34;
        int in = 24;
    }

    public static void cuiEpho() {
        int pu = 71;
        int aur = 7;
        int psos = 9;
        Ilrad.assfe(aur, pu);
    }

    public void bina() {
        Ilrad lurd = new Ilrad(202);
        int mo = 60;
        this.setOss(lurd);
        Ilrad.esaUphash(mo, 9, lurd);
    }

    public static void assfe(int chos, int re) {
        int hi = 41;
        int ho = 10;
        int je = 93;
    }
}
public class Somir {
    private int maNia;
    private Ilrad go;
    private Somir fiss;

    Somir(int maNia) {
        this.maNia = maNia;
    }

    public void setGo(Ilrad go) {
        this.go = go;
    }

    public void setFiss(Somir fiss) {
        this.fiss = fiss;
    }

    public static void wach(int caur) {
        int od = 50;
        int doed = 23;
        int eh = 52;
    }

    public static void fesOdgas(int vi, int pe) {
        Somir.wach(pe);
        HERE;
    }

    public void trisfi() {
        Somir e = new Somir(738);
        new Ilrad(359).ongSchop(this);
        this.setFiss(e);
        new Ilrad(24).bina();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: