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


Given the code below, this method call:

Ladec.rhuHohur();

...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 Ladec {
    private int prer;
    private Quil pae;

    Ladec(int prer) {
        this.prer = prer;
    }

    public void setPae(Quil pae) {
        this.pae = pae;
    }

    public static void giabir() {
        Ladec ra = new Ladec(650);
        Ladec.pris();
        Ladec.ahorn(ra);
    }

    public static void stisi(Quil iwen, Ladec ioom) {
        int toc = 80;
        int pa = 9;
    }

    public static void pris() {
        int adea = 3;
        Ladec bia = new Ladec(931);
        HERE;
    }

    public static void ahorn(Ladec tioc) {
    }

    public static void rhuHohur() {
        Ladec eac = new Ladec(806);
        new Quil(219).ertDiwtra(eac, new Ladec(131), eac);
        new Quil(579).cedna(new Ladec(759), eac);
    }
}
public class Quil {
    private int haSaca;
    private Quil miol;
    private Ladec or;

    Quil(int haSaca) {
        this.haSaca = haSaca;
    }

    public void setMiol(Quil miol) {
        this.miol = miol;
    }

    public void setOr(Ladec or) {
        this.or = or;
    }

    public void ertDiwtra(Ladec erel, Ladec em, Ladec la) {
    }

    public void cedna(Ladec a, Ladec hama) {
        hama.setPae(this);
        Ladec.giabir();
        Ladec.stisi(this, a);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: