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


Given the code below, this method call:

Roie.iaph();

...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 Roie {
    private int nosm;
    private Ong le;

    Roie(int nosm) {
        this.nosm = nosm;
    }

    public void setLe(Ong le) {
        this.le = le;
    }

    public static void didmes() {
        int stil = 85;
        int ijar = 83;
        int gada = 28;
    }

    public static void iaph() {
        Roie.chling(new Roie(784), new Roie(556), new Ong(720));
        Roie.didmes();
    }

    public void ipess(Roie joun) {
        int io = 78;
    }

    public void rhosm(Roie en) {
        Roie gatt = new Roie(325);
        this.ipess(this);
        HERE;
    }

    public static void chling(Roie rac, Roie ramu, Ong tunt) {
        rac.setLe(tunt);
        ramu.rhosm(ramu);
    }
}
public class Ong {
    private int ske;
    private Ong kess;

    Ong(int ske) {
        this.ske = ske;
    }

    public void setKess(Ong kess) {
        this.kess = kess;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: