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


Given the code below, this method call:

Irfle.cedka();

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

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

    public void jopri(Miad er, Miad ia) {
        er.setIs(this);
        HERE;
    }

    public static void icklul(int cel) {
        int wio = 64;
    }

    public static void cedka() {
        new Irfle(841).jopri(new Miad(267), new Miad(674));
        Irfle.icklul(94);
    }
}
public class Miad {
    private int biruc;
    private Irfle is;

    Miad(int biruc) {
        this.biruc = biruc;
    }

    public void setIs(Irfle is) {
        this.is = is;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: