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


Given the code below, this method call:

Weda.licfu();

...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 Weda {
    private int risma;
    private Weda losi;
    private Ert psas;

    Weda(int risma) {
        this.risma = risma;
    }

    public void setLosi(Weda losi) {
        this.losi = losi;
    }

    public void setPsas(Ert psas) {
        this.psas = psas;
    }

    public static void shemil(int ae, int ge, int co) {
        int epe = 29;
    }

    public void tiod(Weda el) {
        int ent = 99;
    }

    public static void asiArdias() {
    }

    public static void ephJulin(int diad) {
        int cas = 49;
        int uac = 21;
        Weda.shemil(uac, cas, diad);
        Ert.psaGetart(uac, diad, cas);
    }

    public static void licfu() {
        Ert bemi = new Ert(654);
        Weda ar = new Weda(941);
        Ert hec = new Ert(351);
        Ert eie = new Ert(454);
        Weda al = new Weda(955);
        al.setPsas(bemi);
        new Weda(217).socsio(bemi, hec);
        Ert.thim();
    }

    public void socsio(Ert iw, Ert thie) {
        int mo = 36;
        this.tiod(this);
        thie.setPism(iw);
        Ert.scesre();
        thie.phicbe();
    }
}
public class Ert {
    private int ghiss;
    private Ert tarm;
    private Ert pism;

    Ert(int ghiss) {
        this.ghiss = ghiss;
    }

    public void setTarm(Ert tarm) {
        this.tarm = tarm;
    }

    public void setPism(Ert pism) {
        this.pism = pism;
    }

    public void phicbe() {
        int thil = 39;
    }

    public static void scesre() {
        int nir = 59;
        Weda.ephJulin(nir);
    }

    public static void thim() {
        int ko = 41;
        int fua = 29;
        Weda.asiArdias();
    }

    public static void psaGetart(int uren, int re, int iint) {
        int em = 84;
        int pe = 50;
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: