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


Given the code below, this method call:

Raar.bemGlong();

...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 Raar {
    private int puFe;
    private Raar ced;
    private Raar ac;

    Raar(int puFe) {
        this.puFe = puFe;
    }

    public void setCed(Raar ced) {
        this.ced = ced;
    }

    public void setAc(Raar ac) {
        this.ac = ac;
    }

    public void qedi(int glu, Raar neng) {
        Irbec.brus(new Irbec(400));
        neng.setAc(this);
        new Raar(787).woec(glu, neng, new Raar(387));
        Raar.wiant(neng);
    }

    public void woec(int ul, Raar nel, Raar mo) {
        int oss = 26;
        mo.setCed(nel);
        Irbec.whewen(this, ul);
    }

    public static void bemGlong() {
        Irbec un = new Irbec(856);
        int plen = 14;
        Raar soor = new Raar(572);
        int ioc = 40;
        Raar ocja = new Raar(686);
        new Raar(418).procle(soor);
        soor.setCed(ocja);
        new Raar(308).qedi(ioc, soor);
    }

    public void procle(Raar me) {
        Raar.ajun();
    }

    public static void esin(int gics) {
        int dese = 61;
        int ent = 69;
    }

    public static void ajun() {
        int daf = 84;
        Irbec mic = new Irbec(886);
        Irbec cem = new Irbec(921);
        Irbec taes = new Irbec(711);
        int swet = 96;
    }

    public static void wiant(Raar oed) {
        int ic = 57;
        int cic = 45;
    }
}
public class Irbec {
    private int heul;
    private Raar rias;
    private Irbec io;

    Irbec(int heul) {
        this.heul = heul;
    }

    public void setRias(Raar rias) {
        this.rias = rias;
    }

    public void setIo(Irbec io) {
        this.io = io;
    }

    public static void stes(int ca, int xois, int plac) {
        int spra = 90;
        int co = 96;
        Raar.esin(co);
        HERE;
    }

    public static void whewen(Raar bost, int si) {
        int spe = 68;
        int ec = 85;
        int jiou = 81;
        Irbec.stes(jiou, ec, si);
    }

    public static void brus(Irbec hou) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: