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


Given the code below, this method call:

Becs.irse();

...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 Becs {
    private int hasco;
    private Becs hi;

    Becs(int hasco) {
        this.hasco = hasco;
    }

    public void setHi(Becs hi) {
        this.hi = hi;
    }

    public static void cesm(Bror zo) {
        int fia = 63;
        zo.grol(zo, fia, zo);
        Becs.glel(fia, zo);
        zo.swoli(zo, fia);
    }

    public void emoos() {
        int to = 68;
        int iss = 0;
        Becs ucat = new Becs(258);
        ucat.cuta();
        this.setHi(ucat);
        Becs.cesm(new Bror(957));
    }

    public static void irse() {
        int ca = 39;
        Becs on = new Becs(336);
        Bror thi = new Bror(923);
        thi.setRi(thi);
        new Becs(124).emoos();
    }

    public static void glel(int scro, Bror stac) {
        int fao = 59;
        int hass = 20;
        HERE;
    }

    public void cuta() {
        Becs o = new Becs(137);
    }
}
public class Bror {
    private int sacir;
    private Becs me;
    private Bror ri;

    Bror(int sacir) {
        this.sacir = sacir;
    }

    public void setMe(Becs me) {
        this.me = me;
    }

    public void setRi(Bror ri) {
        this.ri = ri;
    }

    public void swoli(Bror ste, int ed) {
        int io = 2;
    }

    public void grol(Bror i, int oss, Bror cus) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: