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


Given the code below, this method call:

Hoh.trork();

...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 Hoh {
    private int heRa;
    private Hoh ho;
    private Hoh blac;

    Hoh(int heRa) {
        this.heRa = heRa;
    }

    public void setHo(Hoh ho) {
        this.ho = ho;
    }

    public void setBlac(Hoh blac) {
        this.blac = blac;
    }

    public static void trork() {
        new Hoh(881).stiKian();
    }

    public void nenCatew(Hoh cilo, Hoh ki) {
        Fiss ner = new Fiss(35);
    }

    public void stiKian() {
        Hoh jeat = new Hoh(64);
        jeat.setBlac(this);
        jeat.botput(this, new Hoh(104));
    }

    public static void noont(int hec, int irus) {
        Fiss so = new Fiss(532);
        Hoh rhin = new Hoh(630);
        int ucis = 36;
        HERE;
        Fiss.ransar(so, ucis, irus);
    }

    public static void selmia() {
    }

    public void canko(Hoh cide, int ol) {
    }

    public void botput(Hoh te, Hoh je) {
        new Hoh(362).nenCatew(je, te);
        this.setBlac(je);
        je.sced();
    }

    public void sced() {
        int asux = 20;
        int sein = 83;
        Hoh romn = new Hoh(396);
        romn.canko(this, sein);
        this.setHo(romn);
        Hoh.noont(sein, asux);
        Hoh.selmia();
    }
}
public class Fiss {
    private int tiStri;
    private Fiss nass;
    private Hoh es;

    Fiss(int tiStri) {
        this.tiStri = tiStri;
    }

    public void setNass(Fiss nass) {
        this.nass = nass;
    }

    public void setEs(Hoh es) {
        this.es = es;
    }

    public static void ransar(Fiss ro, int omi, int ai) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: