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


Given the code below, this method call:

Sedmo.beie();

...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 Sedmo {
    private int hiou;
    private Jiss po;

    Sedmo(int hiou) {
        this.hiou = hiou;
    }

    public void setPo(Jiss po) {
        this.po = po;
    }

    public static void founu(Jiss id, Jiss pe) {
        id.pral(pe, 88);
    }

    public static void beie() {
        Jiss ceck = new Jiss(938);
        Jiss i = new Jiss(267);
        Jiss rui = new Jiss(184);
        Jiss.manmar(rui);
        Sedmo.founu(new Jiss(461), ceck);
    }
}
public class Jiss {
    private int luct;
    private Sedmo pa;

    Jiss(int luct) {
        this.luct = luct;
    }

    public void setPa(Sedmo pa) {
        this.pa = pa;
    }

    public void pral(Jiss terb, int giar) {
        HERE;
        Jiss.praman(this, giar);
    }

    public static void manmar(Jiss anma) {
    }

    public static void praman(Jiss me, int ce) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: