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


Given the code below, this method call:

Mio.neacgi();

...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 Mio {
    private int lirim;
    private Ecen nass;
    private Mio rost;

    Mio(int lirim) {
        this.lirim = lirim;
    }

    public void setNass(Ecen nass) {
        this.nass = nass;
    }

    public void setRost(Mio rost) {
        this.rost = rost;
    }

    public static void neacgi() {
        int to = 1;
        Mio.krunt(to, new Mio(976));
        new Ecen(465).sincid();
    }

    public static void krunt(int baeo, Mio se) {
        int diod = 36;
        Ecen crio = new Ecen(823);
    }
}
public class Ecen {
    private int ciSeng;
    private Ecen daa;

    Ecen(int ciSeng) {
        this.ciSeng = ciSeng;
    }

    public void setDaa(Ecen daa) {
        this.daa = daa;
    }

    public void pecSoedam(Ecen oias) {
        Ecen la = new Ecen(79);
        this.setDaa(la);
        Ecen.couc(oias, this, la);
    }

    public static void couc(Ecen nir, Ecen susm, Ecen knod) {
        Ecen pti = new Ecen(715);
        knod.ritoc(pti, nir, knod);
        HERE;
    }

    public void sincid() {
        int rhi = 52;
        this.setDaa(this);
        new Ecen(893).pecSoedam(this);
        Ecen.wouHeint(rhi, new Ecen(705), this);
    }

    public static void wouHeint(int gi, Ecen sa, Ecen hihu) {
    }

    public void ritoc(Ecen gle, Ecen ico, Ecen veck) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: