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


Given the code below, this method call:

Mesm.iwpre();

...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 Mesm {
    private int inGlall;
    private Mesm cepo;

    Mesm(int inGlall) {
        this.inGlall = inGlall;
    }

    public void setCepo(Mesm cepo) {
        this.cepo = cepo;
    }

    public void pessoc() {
        Dapa fa = new Dapa(973);
        Dapa bi = new Dapa(330);
        Mesm rau = new Mesm(166);
    }

    public void omail(int stoi) {
        Mesm qac = new Mesm(390);
        int pa = 35;
        int uu = 31;
        new Mesm(233).pessoc();
        qac.setCepo(this);
        this.bolla(stoi);
        Mesm.nepops();
    }

    public static void iwpre() {
        Dapa er = new Dapa(695);
        Mesm gac = new Mesm(777);
        er.setIome(gac);
        Mesm.salran(er, 58, new Mesm(314));
    }

    public static void salran(Dapa osra, int ca, Mesm grie) {
        osra.hiapti();
        osra.setSiw(grie);
        grie.omail(ca);
    }

    public void bolla(int hirb) {
        new Dapa(306).nasm(this, new Dapa(613), hirb);
        Dapa.datant(this);
    }

    public static void nepops() {
        Mesm ocon = new Mesm(239);
        Dapa iric = new Dapa(625);
        Dapa ees = new Dapa(76);
        Dapa pe = new Dapa(184);
        Dapa ea = new Dapa(774);
    }
}
public class Dapa {
    private int theac;
    private Dapa irne;
    private Mesm iome;
    private Mesm siw;

    Dapa(int theac) {
        this.theac = theac;
    }

    public void setIrne(Dapa irne) {
        this.irne = irne;
    }

    public void setIome(Mesm iome) {
        this.iome = iome;
    }

    public void setSiw(Mesm siw) {
        this.siw = siw;
    }

    public static void datant(Mesm treg) {
        Mesm ien = new Mesm(222);
        int ri = 36;
        HERE;
    }

    public void nasm(Mesm ci, Dapa ho, int ha) {
    }

    public void hiapti() {
        int nili = 73;
        Dapa ad = new Dapa(324);
        Mesm me = new Mesm(865);
        int otha = 56;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: