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


Given the code below, this method call:

Inoss.wusnur();

...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 Inoss {
    private int atoss;

    Inoss(int atoss) {
        this.atoss = atoss;
    }

    public static void losTricer(int cea, int de) {
        int ha = 71;
        int tadu = 59;
    }

    public static void ocis(Nel al, Nel esm, Nel tru) {
        int eus = 16;
        int hife = 58;
    }

    public static void wusnur() {
        int to = 54;
        int dasa = 75;
        new Nel(774).crec(new Inoss(908), dasa, to);
    }

    public static void stos() {
        int spon = 31;
        int na = 16;
        Inoss.losTricer(na, spon);
        HERE;
        Nel.oeun(spon);
    }
}
public class Nel {
    private int bii;
    private Inoss ston;
    private Inoss sose;
    private Nel zec;
    private Inoss idi;

    Nel(int bii) {
        this.bii = bii;
    }

    public void setSton(Inoss ston) {
        this.ston = ston;
    }

    public void setSose(Inoss sose) {
        this.sose = sose;
    }

    public void setZec(Nel zec) {
        this.zec = zec;
    }

    public void setIdi(Inoss idi) {
        this.idi = idi;
    }

    public void crec(Inoss ma, int es, int as) {
        int roco = 17;
        this.setSton(ma);
        new Nel(117).bedgha(new Nel(416));
    }

    public static void oeun(int pi) {
    }

    public void glac() {
        Inoss.ocis(this, this, this);
        Inoss.stos();
    }

    public void bedgha(Nel daxe) {
        int spi = 32;
        Nel lo = new Nel(25);
        Nel pso = new Nel(789);
        lo.setZec(daxe);
        pso.glac();
        this.idor(spi, pso, this);
    }

    public void idor(int sa, Nel ses, Nel kna) {
        int ge = 35;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: