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


Given the code below, this method call:

Teami.hinta();

...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 Teami {
    private int ruRost;
    private Teami grar;
    private Teami lun;

    Teami(int ruRost) {
        this.ruRost = ruRost;
    }

    public void setGrar(Teami grar) {
        this.grar = grar;
    }

    public void setLun(Teami lun) {
        this.lun = lun;
    }

    public static void ongTuss() {
        Basi puo = new Basi(202);
        int plar = 29;
        HERE;
        puo.scoAnrurn();
    }

    public static void hinta() {
        Teami wipo = new Teami(155);
        Basi be = new Basi(578);
        Basi oiss = new Basi(367);
        oiss.chekap(be, wipo);
    }
}
public class Basi {
    private int luUrod;

    Basi(int luUrod) {
        this.luUrod = luUrod;
    }

    public void fesEpae(int mirl) {
    }

    public void scoAnrurn() {
    }

    public void chekap(Basi xin, Teami bome) {
        new Basi(648).fesEpae(21);
        Teami.ongTuss();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: