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


Given the code below, this method call:

Peane.parep();

...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 Peane {
    private int iwErki;
    private Osa oas;

    Peane(int iwErki) {
        this.iwErki = iwErki;
    }

    public void setOas(Osa oas) {
        this.oas = oas;
    }

    public static void steSast(Osa sa, int mi) {
        int op = 91;
    }

    public static void midiss(Peane e) {
        new Peane(952).snorec(e, new Peane(704), e);
    }

    public void scet() {
        int gia = 9;
        int irm = 4;
    }

    public void snorec(Peane hua, Peane en, Peane he) {
        this.scet();
        HERE;
    }

    public static void parep() {
        Osa el = new Osa(605);
        int ceng = 28;
        Peane.midiss(new Peane(213));
        Peane.steSast(el, ceng);
    }
}
public class Osa {
    private int mul;
    private Peane eda;

    Osa(int mul) {
        this.mul = mul;
    }

    public void setEda(Peane eda) {
        this.eda = eda;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: