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


Given the code below, this method call:

Sebia.fosEsm();

...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 Sebia {
    private int geChoss;
    private Wiaff eti;
    private Sebia seni;

    Sebia(int geChoss) {
        this.geChoss = geChoss;
    }

    public void setEti(Wiaff eti) {
        this.eti = eti;
    }

    public void setSeni(Sebia seni) {
        this.seni = seni;
    }

    public void phror(Wiaff oce) {
        Sebia hess = new Sebia(282);
    }

    public void tregli(Wiaff rike, int ahe) {
        Wiaff mert = new Wiaff(783);
        int pide = 78;
        mert.setSchi(this);
        new Sebia(535).ackan(pide, ahe);
        mert.montdu(rike, ahe);
    }

    public void ackan(int chro, int aiec) {
        int whu = 98;
        this.setSeni(this);
        this.bromp(chro, whu, aiec);
    }

    public void bromp(int aa, int di, int idac) {
        int ur = 61;
        Wiaff.ocuPleess(aa, ur);
    }

    public static void fosEsm() {
        Sebia sian = new Sebia(791);
        Wiaff nift = new Wiaff(146);
        Wiaff tud = new Wiaff(46);
        nift.trint();
        tud.setVarm(nift);
        new Sebia(115).tregli(tud, 71);
    }
}
public class Wiaff {
    private int taenx;
    private Sebia schi;
    private Wiaff varm;

    Wiaff(int taenx) {
        this.taenx = taenx;
    }

    public void setSchi(Sebia schi) {
        this.schi = schi;
    }

    public void setVarm(Wiaff varm) {
        this.varm = varm;
    }

    public static void ocuPleess(int tris, int cebe) {
        int ti = 7;
        Wiaff.blosm(ti);
        HERE;
        Wiaff.sihian(ti);
    }

    public void montdu(Wiaff poff, int sor) {
    }

    public static void sihian(int meca) {
    }

    public void trint() {
        Sebia ei = new Sebia(99);
        new Sebia(50).phror(this);
    }

    public static void blosm(int at) {
        int sirk = 84;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: