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


Given the code below, this method call:

Schia.bosm();

...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 Schia {
    private int posto;

    Schia(int posto) {
        this.posto = posto;
    }

    public void husMoelia(Schia hiaa, Schia erch, Schia gi) {
    }

    public void jeous(Eac cle) {
        cle.setNer(this);
        new Schia(935).cicced();
        cle.iose(this, cle, this);
    }

    public static void bosm() {
        Schia ced = new Schia(872);
        ced.husMoelia(new Schia(520), ced, ced);
        ced.jeous(new Eac(623));
    }

    public void asgi(Eac cao) {
        int it = 46;
        int ce = 43;
    }

    public void cicced() {
        Schia si = new Schia(964);
        Eac me = new Eac(387);
        int waha = 69;
        me.setNer(si);
        Eac.acsio(waha);
        this.asgi(me);
    }
}
public class Eac {
    private int cunon;
    private Schia ner;
    private Schia dren;
    private Eac uc;

    Eac(int cunon) {
        this.cunon = cunon;
    }

    public void setNer(Schia ner) {
        this.ner = ner;
    }

    public void setDren(Schia dren) {
        this.dren = dren;
    }

    public void setUc(Eac uc) {
        this.uc = uc;
    }

    public void iose(Schia suro, Eac os, Schia ri) {
    }

    public static void acsio(int akqa) {
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: