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


Given the code below, this method call:

Maith.ounUdrans();

...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 Maith {
    private int ceo;

    Maith(int ceo) {
        this.ceo = ceo;
    }

    public void diirf() {
        Maith fios = new Maith(91);
    }

    public static void ounUdrans() {
        Anic resm = new Anic(128);
        Anic pe = new Anic(792);
        new Maith(217).diirf();
        pe.whunt(resm, pe);
    }
}
public class Anic {
    private int niOrm;
    private Maith fio;

    Anic(int niOrm) {
        this.niOrm = niOrm;
    }

    public void setFio(Maith fio) {
        this.fio = fio;
    }

    public void whunt(Anic teie, Anic eoc) {
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: