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


Given the code below, this method call:

Dasm.osphes();

...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 Dasm {
    private int ede;
    private Cirm tu;

    Dasm(int ede) {
        this.ede = ede;
    }

    public void setTu(Cirm tu) {
        this.tu = tu;
    }

    public static void sorce(Dasm iow) {
        new Cirm(765).triada(new Dasm(354));
        HERE;
    }

    public void chre(Cirm cial) {
        int hur = 23;
        Cirm.cring(new Dasm(684), cial);
        this.setTu(cial);
        Dasm.sorce(this);
    }

    public static void osphes() {
        Dasm rerd = new Dasm(190);
        int phas = 50;
        int oma = 22;
        Dasm tini = new Dasm(478);
        new Cirm(789).estcec();
    }
}
public class Cirm {
    private int damu;
    private Cirm at;
    private Cirm ves;
    private Dasm splu;

    Cirm(int damu) {
        this.damu = damu;
    }

    public void setAt(Cirm at) {
        this.at = at;
    }

    public void setVes(Cirm ves) {
        this.ves = ves;
    }

    public void setSplu(Dasm splu) {
        this.splu = splu;
    }

    public void vosOrel(Dasm ica, int bi, Cirm dasa) {
        Dasm spol = new Dasm(833);
    }

    public static void eouDerin(Cirm stri, Cirm osk) {
        int hus = 57;
        Cirm irhu = new Cirm(518);
    }

    public void triul(Cirm brer) {
        int itan = 40;
        int peno = 66;
        this.setAt(brer);
        new Dasm(168).chre(brer);
    }

    public static void cring(Dasm bre, Cirm da) {
    }

    public void triada(Dasm puis) {
    }

    public void estcec() {
        this.vosOrel(new Dasm(835), 80, this);
        new Cirm(433).triul(this);
        Cirm.eouDerin(new Cirm(1), this);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: