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


Given the code below, this method call:

Sasou.stec();

...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 Sasou {
    private int eou;

    Sasou(int eou) {
        this.eou = eou;
    }

    public void cepo(Enme hea) {
        hea.setCe(hea);
        HERE;
        this.ganis(this, hea, hea);
    }

    public static void stec() {
        Sasou fo = new Sasou(416);
        new Sasou(372).cepo(new Enme(661));
    }

    public void ganis(Sasou ul, Enme e, Enme ina) {
    }
}
public class Enme {
    private int alBe;
    private Enme ce;

    Enme(int alBe) {
        this.alBe = alBe;
    }

    public void setCe(Enme ce) {
        this.ce = ce;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: