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


Given the code below, this method call:

Poceb.jisSetbi();

...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 Poceb {
    private int bacna;

    Poceb(int bacna) {
        this.bacna = bacna;
    }

    public void rhad(Diw ku) {
        HERE;
    }

    public static void jisSetbi() {
        Diw lu = new Diw(178);
        new Poceb(596).rhad(new Diw(397));
        lu.mihu(lu, lu, lu);
    }
}
public class Diw {
    private int undhe;
    private Poceb pril;

    Diw(int undhe) {
        this.undhe = undhe;
    }

    public void setPril(Poceb pril) {
        this.pril = pril;
    }

    public void mihu(Diw gino, Diw si, Diw be) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: