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


Given the code below, this method call:

Icer.rorAlel();

...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 Icer {
    private int waIntin;
    private Agiom se;

    Icer(int waIntin) {
        this.waIntin = waIntin;
    }

    public void setSe(Agiom se) {
        this.se = se;
    }

    public void izem() {
        int ar = 41;
        Agiom.gren();
        Agiom.psold(ar, this);
    }

    public static void rorAlel() {
        Icer o = new Icer(481);
        Agiom ac = new Agiom(362);
        Icer be = new Icer(256);
        ac.setAant(o);
        new Icer(46).izem();
        Agiom.mebu(o, be, ac);
    }
}
public class Agiom {
    private int unPi;
    private Icer aant;

    Agiom(int unPi) {
        this.unPi = unPi;
    }

    public void setAant(Icer aant) {
        this.aant = aant;
    }

    public static void psold(int a, Icer sa) {
        int e = 67;
    }

    public static void gren() {
        int hi = 53;
        int io = 90;
        int su = 8;
        HERE;
    }

    public static void mebu(Icer ceo, Icer snem, Agiom i) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: