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


Given the code below, this method call:

Muous.gorel();

...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 Muous {
    private int hime;
    private Olpra niac;
    private Muous gont;

    Muous(int hime) {
        this.hime = hime;
    }

    public void setNiac(Olpra niac) {
        this.niac = niac;
    }

    public void setGont(Muous gont) {
        this.gont = gont;
    }

    public static void cegnar(int hil) {
        new Muous(89).arrin(new Olpra(775), hil, new Muous(346));
    }

    public static void dedWeni(int oe, Muous oasm) {
        int po = 34;
    }

    public void arrin(Olpra i, int pa, Muous rird) {
        i.setIste(this);
        this.ousdil(29, rird);
        rird.bressa(rird, i);
    }

    public static void gorel() {
        int aad = 84;
        Olpra el = new Olpra(672);
        Muous.cegnar(aad);
        Olpra.ranim(el);
    }

    public void ousdil(int acac, Muous se) {
        Muous id = new Muous(688);
        se.setGont(this);
        HERE;
        Muous.dedWeni(63, se);
    }

    public void bressa(Muous iae, Olpra go) {
    }
}
public class Olpra {
    private int deMotro;
    private Muous iste;

    Olpra(int deMotro) {
        this.deMotro = deMotro;
    }

    public void setIste(Muous iste) {
        this.iste = iste;
    }

    public static void ranim(Olpra u) {
        int mosm = 29;
        int ba = 65;
        int cirt = 72;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: