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


Given the code below, this method call:

Dugea.tria();

...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 Dugea {
    private int doues;
    private Aedi hi;

    Dugea(int doues) {
        this.doues = doues;
    }

    public void setHi(Aedi hi) {
        this.hi = hi;
    }

    public static void tria() {
        new Dugea(770).omec(48, new Aedi(225), new Aedi(819));
        new Aedi(870).eskir();
    }

    public void omec(int dio, Aedi is, Aedi i) {
    }
}
public class Aedi {
    private int cespu;

    Aedi(int cespu) {
        this.cespu = cespu;
    }

    public void eskir() {
        Dugea miar = new Dugea(769);
        miar.setHi(this);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: