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


Given the code below, this method call:

Oec.stic();

...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 Oec {
    private int fahe;
    private Oec noe;

    Oec(int fahe) {
        this.fahe = fahe;
    }

    public void setNoe(Oec noe) {
        this.noe = noe;
    }

    public static void stic() {
        Oec no = new Oec(383);
        Ril jo = new Ril(819);
        Ril.urpead();
        no.setNoe(no);
        Ril.omart(new Ril(603), jo);
    }
}
public class Ril {
    private int giMoodi;

    Ril(int giMoodi) {
        this.giMoodi = giMoodi;
    }

    public static void urpead() {
    }

    public static void omart(Ril cuoc, Ril esm) {
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: