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


Given the code below, this method call:

Bri.ewiAsmoc();

...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 Bri {
    private int unEdur;
    private Mucap peir;
    private Bri oph;

    Bri(int unEdur) {
        this.unEdur = unEdur;
    }

    public void setPeir(Mucap peir) {
        this.peir = peir;
    }

    public void setOph(Bri oph) {
        this.oph = oph;
    }

    public static void ewiAsmoc() {
        Mucap saac = new Mucap(724);
        Bri ma = new Bri(423);
        Mucap zi = new Mucap(809);
        int sest = 76;
        int siqa = 52;
        ma.setPeir(saac);
        Mucap.iupsia();
    }

    public static void bocs() {
        int we = 12;
        Mucap va = new Mucap(454);
        int ia = 28;
        int aat = 34;
        int mies = 26;
        Mucap.flarb(we, ia, mies);
        va.setEsm(va);
        va.owhem(ia, we);
    }

    public void thosma(Mucap ic, int vi, Bri rouu) {
    }
}
public class Mucap {
    private int fler;
    private Mucap esm;
    private Bri idu;

    Mucap(int fler) {
        this.fler = fler;
    }

    public void setEsm(Mucap esm) {
        this.esm = esm;
    }

    public void setIdu(Bri idu) {
        this.idu = idu;
    }

    public void snon() {
    }

    public static void oteAco(Mucap mip) {
        int tion = 75;
        Bri diob = new Bri(520);
        new Bri(351).thosma(mip, tion, diob);
        mip.setIdu(diob);
        Bri.bocs();
    }

    public static void iupsia() {
        Mucap olfe = new Mucap(265);
        Mucap.oteAco(olfe);
        Mucap.nopTrert(olfe, olfe);
    }

    public static void nopTrert(Mucap ke, Mucap omot) {
        int mo = 40;
        int scio = 15;
        int alri = 52;
    }

    public void owhem(int bect, int basm) {
        int ishe = 97;
        this.snon();
        HERE;
    }

    public static void flarb(int za, int psom, int thel) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: