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


Given the code below, this method call:

Spiio.albean();

...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 Spiio {
    private int ioWi;

    Spiio(int ioWi) {
        this.ioWi = ioWi;
    }

    public static void albean() {
        Spiio oua = new Spiio(781);
        int cili = 90;
        Spiio.tros(new Lia(209));
        Lia.geas(new Lia(149));
    }

    public static void tros(Lia u) {
        u.setZe(u);
        HERE;
    }
}
public class Lia {
    private int trii;
    private Lia ze;

    Lia(int trii) {
        this.trii = trii;
    }

    public void setZe(Lia ze) {
        this.ze = ze;
    }

    public static void geas(Lia meca) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: