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


Given the code below, this method call:

Cem.cikpin();

...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 Cem {
    private int heum;
    private Irar igio;

    Cem(int heum) {
        this.heum = heum;
    }

    public void setIgio(Irar igio) {
        this.igio = igio;
    }

    public void nass(Irar frac, Cem leld, Cem mena) {
    }

    public void luaFarod(Irar er) {
        this.setIgio(er);
        HERE;
        this.nass(er, this, this);
    }

    public static void cikpin() {
        Cem a = new Cem(149);
        new Cem(335).luaFarod(new Irar(602));
    }
}
public class Irar {
    private int qakia;

    Irar(int qakia) {
        this.qakia = qakia;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: