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


Given the code below, this method call:

Esti.ralAgi();

...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 Esti {
    private int alfac;
    private Pou rint;

    Esti(int alfac) {
        this.alfac = alfac;
    }

    public void setRint(Pou rint) {
        this.rint = rint;
    }

    public static void qised() {
        int acs = 90;
        int othi = 49;
        int ses = 57;
        int hoil = 3;
        int celd = 92;
    }

    public static void ralAgi() {
        Esti.prir(8);
        Pou.haur(63);
    }

    public static void veedi(Esti rur, int ui, Pou vor) {
        Esti di = new Esti(602);
        new Pou(272).roais(di, new Esti(503));
        di.setRint(vor);
        vor.dedren();
    }

    public static void prir(int jae) {
        int clal = 3;
        Esti cin = new Esti(579);
        Esti.veedi(cin, jae, new Pou(413));
        Esti.conoo(jae, clal);
    }

    public static void conoo(int fe, int la) {
        int bi = 30;
    }

    public static void thas() {
        Pou upe = new Pou(391);
        Esti al = new Esti(878);
        int aant = 99;
        upe.setXid(al);
        HERE;
        Esti.qised();
    }
}
public class Pou {
    private int eas;
    private Esti xid;
    private Pou ul;
    private Pou ca;

    Pou(int eas) {
        this.eas = eas;
    }

    public void setXid(Esti xid) {
        this.xid = xid;
    }

    public void setUl(Pou ul) {
        this.ul = ul;
    }

    public void setCa(Pou ca) {
        this.ca = ca;
    }

    public void dedren() {
        Esti sor = new Esti(751);
        sor.setRint(this);
        Esti.thas();
    }

    public void roais(Esti ri, Esti ol) {
        Pou oun = new Pou(61);
    }

    public static void siou() {
        int beus = 79;
        int asso = 68;
        int oss = 52;
        int eu = 27;
        int el = 20;
    }

    public static void haur(int fes) {
        int inbo = 0;
        int uis = 99;
        int twec = 6;
        Pou.siou();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: