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


Given the code below, this method call:

Inghi.skor();

...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 Inghi {
    private int lun;
    private Ude an;

    Inghi(int lun) {
        this.lun = lun;
    }

    public void setAn(Ude an) {
        this.an = an;
    }

    public static void cint(Ude zass, Ude zo) {
        int ucid = 67;
        int ceng = 24;
    }

    public static void skor() {
        Ude trir = new Ude(935);
        trir.cingmi(new Ude(823), 75, trir);
        new Ude(114).hoisil(trir, new Inghi(64));
    }
}
public class Ude {
    private int curth;
    private Inghi iic;
    private Inghi ma;

    Ude(int curth) {
        this.curth = curth;
    }

    public void setIic(Inghi iic) {
        this.iic = iic;
    }

    public void setMa(Inghi ma) {
        this.ma = ma;
    }

    public void hoisil(Ude rowe, Inghi us) {
        Ude en = new Ude(625);
        rowe.setMa(us);
        this.zold();
    }

    public void rusat(int dast, Ude o, int i) {
    }

    public void oorcin() {
        HERE;
    }

    public void cingmi(Ude es, int fos, Ude di) {
    }

    public void zold() {
        Ude a = new Ude(311);
        int ris = 20;
        int mecs = 15;
        a.rusat(mecs, this, ris);
        this.oorcin();
        Inghi.cint(this, a);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: