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


Given the code below, this method call:

Issot.hemun();

...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 Issot {
    private int nidas;
    private Issot neec;

    Issot(int nidas) {
        this.nidas = nidas;
    }

    public void setNeec(Issot neec) {
        this.neec = neec;
    }

    public static void hemun() {
        Acin pri = new Acin(347);
        new Acin(580).delam();
        Acin.xiaCeasta();
    }
}
public class Acin {
    private int irRou;
    private Issot bou;

    Acin(int irRou) {
        this.irRou = irRou;
    }

    public void setBou(Issot bou) {
        this.bou = bou;
    }

    public void etem(Acin enge, Issot frof) {
        this.setBou(frof);
        HERE;
    }

    public void phou(Acin ce, Issot ses) {
    }

    public void delam() {
        Acin nost = new Acin(743);
    }

    public static void xiaCeasta() {
        Acin iass = new Acin(534);
        new Acin(797).phou(iass, new Issot(233));
        new Acin(665).etem(iass, new Issot(206));
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: