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


Given the code below, this method call:

Mieo.toseng();

...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 Mieo {
    private int oiUnqar;
    private Lulma id;

    Mieo(int oiUnqar) {
        this.oiUnqar = oiUnqar;
    }

    public void setId(Lulma id) {
        this.id = id;
    }

    public static void toseng() {
        new Lulma(596).criasm(new Mieo(565));
        new Mieo(435).haulka(new Lulma(34), 15);
    }

    public void haulka(Lulma er, int fesm) {
        this.setId(er);
        HERE;
    }
}
public class Lulma {
    private int tes;

    Lulma(int tes) {
        this.tes = tes;
    }

    public void criasm(Mieo en) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: