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


Given the code below, this method call:

Siou.colser();

...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 Siou {
    private int teAchad;
    private Diac od;
    private Diac siil;

    Siou(int teAchad) {
        this.teAchad = teAchad;
    }

    public void setOd(Diac od) {
        this.od = od;
    }

    public void setSiil(Diac siil) {
        this.siil = siil;
    }

    public static void ceiRuis(Siou prir) {
        int qi = 62;
    }

    public static void alfid() {
        Siou.odcar(97, 61);
    }

    public static void ciwDiost() {
        int ta = 41;
    }

    public void beeph() {
        Diac fe = new Diac(431);
        int aner = 95;
        int pliu = 45;
        this.setSiil(fe);
        new Siou(190).stuk();
    }

    public static void quxe() {
        int ri = 12;
        int ebi = 13;
        int dass = 65;
        int eec = 55;
        int ec = 50;
    }

    public static void colser() {
        Diac thi = new Diac(297);
        Siou mur = new Siou(754);
        new Diac(885).ruip(mur);
        thi.setFa(mur);
        new Siou(34).beeph();
    }

    public void stuk() {
        Diac aiw = new Diac(929);
        int or = 95;
        Siou.ceiRuis(this);
        this.setOd(aiw);
        Siou.alfid();
        Siou.quxe();
    }

    public static void odcar(int ol, int iouk) {
        int of = 15;
        HERE;
        Siou.ciwDiost();
    }
}
public class Diac {
    private int stiu;
    private Diac deng;
    private Siou fa;

    Diac(int stiu) {
        this.stiu = stiu;
    }

    public void setDeng(Diac deng) {
        this.deng = deng;
    }

    public void setFa(Siou fa) {
        this.fa = fa;
    }

    public void ruip(Siou chod) {
        Diac o = new Diac(265);
        o.feards(o, 80);
    }

    public void feards(Diac jor, int cer) {
        Diac ne = new Diac(331);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: