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


Given the code below, this method call:

Fixfi.ialShom();

...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 Fixfi {
    private int eale;

    Fixfi(int eale) {
        this.eale = eale;
    }

    public static void ialShom() {
        new Hibia(469).emcost(new Fixfi(950), new Fixfi(214), new Fixfi(120));
    }

    public void asmurn() {
        int helt = 51;
    }
}
public class Hibia {
    private int asme;
    private Fixfi as;

    Hibia(int asme) {
        this.asme = asme;
    }

    public void setAs(Fixfi as) {
        this.as = as;
    }

    public void emcost(Fixfi ee, Fixfi pana, Fixfi sqar) {
        this.setAs(pana);
        HERE;
        ee.asmurn();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: