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


Given the code below, this method call:

Tomme.hesia();

...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 Tomme {
    private int hiShar;

    Tomme(int hiShar) {
        this.hiShar = hiShar;
    }

    public void aunMesmit() {
        int ta = 59;
        new Tomme(865).chaod(ta, this);
    }

    public static void hesia() {
        Tomme iid = new Tomme(550);
        Tomme qe = new Tomme(535);
        int qent = 52;
        Tomme cic = new Tomme(892);
        new Tomme(600).aunMesmit();
        iid.cendi();
    }

    public void uhon() {
        int kein = 81;
        int si = 21;
        int u = 16;
    }

    public static void nengse(int ea, int lel) {
    }

    public void cendi() {
        int rou = 14;
    }

    public void chaod(int ni, Tomme zog) {
        int isi = 9;
        Ocoss.orgax(this, ni, isi);
        zog.uhon();
    }
}
public class Ocoss {
    private int laIpras;
    private Tomme thas;
    private Ocoss ko;
    private Ocoss slin;

    Ocoss(int laIpras) {
        this.laIpras = laIpras;
    }

    public void setThas(Tomme thas) {
        this.thas = thas;
    }

    public void setKo(Ocoss ko) {
        this.ko = ko;
    }

    public void setSlin(Ocoss slin) {
        this.slin = slin;
    }

    public static void orgax(Tomme ipip, int cu, int tu) {
        Tomme.nengse(tu, cu);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: