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


Given the code below, this method call:

Aass.bessuk();

...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 Aass {
    private int khil;
    private Aass on;
    private Agh seol;

    Aass(int khil) {
        this.khil = khil;
    }

    public void setOn(Aass on) {
        this.on = on;
    }

    public void setSeol(Agh seol) {
        this.seol = seol;
    }

    public void asba() {
        int pesm = 11;
    }

    public static void bissar(int es, int du) {
        int drel = 38;
        int ior = 1;
        HERE;
        Agh.tentse(drel, es, du);
    }

    public void goom() {
        int go = 18;
    }

    public static void bessuk() {
        int fom = 84;
        Agh sa = new Agh(722);
        Agh.venShuss(new Aass(575), sa, fom);
    }

    public static void poes(Aass vi, Aass cilo) {
    }

    public void saoss() {
        int ploe = 20;
        int cec = 18;
        int stas = 7;
        int daba = 24;
        this.setOn(this);
        Aass.bissar(stas, daba);
    }
}
public class Agh {
    private int sudpi;
    private Aass oc;
    private Aass pa;

    Agh(int sudpi) {
        this.sudpi = sudpi;
    }

    public void setOc(Aass oc) {
        this.oc = oc;
    }

    public void setPa(Aass pa) {
        this.pa = pa;
    }

    public static void entOcfo() {
        Aass proe = new Aass(711);
        Aass cout = new Aass(504);
        Aass nuwi = new Aass(642);
        int tro = 73;
        int elqe = 62;
        Aass.poes(proe, nuwi);
        cout.setOn(proe);
        cout.saoss();
        nuwi.goom();
    }

    public static void venShuss(Aass dril, Agh etul, int enas) {
        Aass tirm = new Aass(537);
        tirm.setSeol(etul);
        Agh.entOcfo();
        tirm.asba();
    }

    public static void tentse(int deni, int molo, int rir) {
        int ptus = 69;
        int phe = 58;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: