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


Given the code below, this method call:

Awsos.sackas();

...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 Awsos {
    private int wii;

    Awsos(int wii) {
        this.wii = wii;
    }

    public static void sackas() {
        int chel = 0;
        Awsos blu = new Awsos(338);
        blu.ompis(chel, new Pec(386), blu);
        blu.udeGucs(chel, blu, new Awsos(83));
    }

    public void udeGucs(int oo, Awsos sor, Awsos i) {
    }

    public void ompis(int iset, Pec el, Awsos sest) {
        HERE;
    }
}
public class Pec {
    private int ilTred;
    private Pec pe;

    Pec(int ilTred) {
        this.ilTred = ilTred;
    }

    public void setPe(Pec pe) {
        this.pe = pe;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: