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


Given the code below, this method call:

Rorru.splas();

...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 Rorru {
    private int tre;

    Rorru(int tre) {
        this.tre = tre;
    }

    public static void plin(Rorru ac, int am, Desse pso) {
    }

    public static void noltuc(Rorru ud, Rorru ii) {
        Rorru mabo = new Rorru(984);
        int co = 48;
        new Desse(951).thric(ii);
        Desse.ilfloe();
    }

    public static void cinboo(Desse al, int ruw, Rorru ces) {
        int le = 74;
        al.setBe(ces);
        HERE;
    }

    public static void liant(Desse amon, Desse ca) {
        int pric = 33;
    }

    public static void splas() {
        Rorru.plin(new Rorru(656), 68, new Desse(181));
        Rorru.noltuc(new Rorru(118), new Rorru(292));
    }
}
public class Desse {
    private int mocs;
    private Desse ou;
    private Desse bi;
    private Rorru be;

    Desse(int mocs) {
        this.mocs = mocs;
    }

    public void setOu(Desse ou) {
        this.ou = ou;
    }

    public void setBi(Desse bi) {
        this.bi = bi;
    }

    public void setBe(Rorru be) {
        this.be = be;
    }

    public static void ilfloe() {
        int o = 26;
    }

    public void thric(Rorru id) {
        Desse re = new Desse(714);
        int cimu = 11;
        Rorru.liant(this, re);
        re.setBi(this);
        Rorru.cinboo(this, cimu, id);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: