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


Given the code below, this method call:

Bem.bifdun();

...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 Bem {
    private int ror;
    private Bem maec;

    Bem(int ror) {
        this.ror = ror;
    }

    public void setMaec(Bem maec) {
        this.maec = maec;
    }

    public static void jinhe(int so) {
        int apri = 73;
        int smil = 27;
    }

    public void thod(Asasm dass, Bem bi) {
    }

    public void sless(int iaac, Asasm me, Bem edi) {
        this.setMaec(edi);
        HERE;
    }

    public static void bifdun() {
        int psit = 19;
        Bem.chre(psit, new Asasm(654), new Bem(408));
        Bem.jinhe(psit);
    }

    public static void chre(int na, Asasm iea, Bem i) {
        new Bem(276).thod(new Asasm(403), i);
        iea.setSe(iea);
        new Bem(147).sless(na, iea, new Bem(662));
    }
}
public class Asasm {
    private int ous;
    private Asasm se;

    Asasm(int ous) {
        this.ous = ous;
    }

    public void setSe(Asasm se) {
        this.se = se;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: