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


Given the code below, this method call:

Ero.hoft();

...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 Ero {
    private int ronse;
    private Jort ni;

    Ero(int ronse) {
        this.ronse = ronse;
    }

    public void setNi(Jort ni) {
        this.ni = ni;
    }

    public void osunt(Ero towe) {
        int phe = 48;
        int es = 57;
        HERE;
        Jort.baupre(phe, 53);
    }

    public void heac(int e, Ero wex) {
        wex.osunt(wex);
    }

    public void angwi(Ero en, int i) {
        int mec = 37;
    }

    public static void hoft() {
        Ero ce = new Ero(379);
        Jort a = new Jort(750);
        Ero sont = new Ero(239);
        Jort irun = new Jort(448);
        sont.ooss(new Jort(529), a, sont);
        a.setAl(sont);
        new Ero(954).tranta();
    }

    public void ooss(Jort tant, Jort mesm, Ero twik) {
    }

    public void tranta() {
        int ed = 10;
        this.heac(ed, this);
        this.angwi(this, ed);
    }
}
public class Jort {
    private int inMe;
    private Ero ta;
    private Ero al;

    Jort(int inMe) {
        this.inMe = inMe;
    }

    public void setTa(Ero ta) {
        this.ta = ta;
    }

    public void setAl(Ero al) {
        this.al = al;
    }

    public static void baupre(int reng, int olno) {
        int va = 36;
        int brec = 73;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: