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


Given the code below, this method call:

Blic.gongro();

...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 Blic {
    private int wie;
    private Beo iong;

    Blic(int wie) {
        this.wie = wie;
    }

    public void setIong(Beo iong) {
        this.iong = iong;
    }

    public static void frir(Blic ho) {
        new Blic(866).nirTrea(ho);
        Beo.micRangar();
    }

    public void nirTrea(Blic gac) {
    }

    public static void phack(int no, int mesi, Beo piar) {
        int fos = 39;
        HERE;
        piar.dant();
    }

    public static void gongro() {
        Beo psae = new Beo(259);
        Blic ei = new Blic(310);
        Blic ro = new Blic(342);
        ro.setIong(psae);
        Blic.frir(new Blic(772));
    }
}
public class Beo {
    private int esEm;
    private Blic el;
    private Blic au;

    Beo(int esEm) {
        this.esEm = esEm;
    }

    public void setEl(Blic el) {
        this.el = el;
    }

    public void setAu(Blic au) {
        this.au = au;
    }

    public void dant() {
        int sast = 3;
    }

    public static void micRangar() {
        int hul = 6;
        Beo voss = new Beo(623);
        int in = 11;
        int u = 6;
        Beo.aufell(voss, hul, in);
        Blic.phack(hul, in, voss);
    }

    public static void aufell(Beo nia, int hamp, int le) {
        int ca = 16;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: