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


Given the code below, this method call:

Nawse.depfa();

...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 Nawse {
    private int oaTru;
    private Nawse pi;
    private Nawse ril;
    private Nawse niss;

    Nawse(int oaTru) {
        this.oaTru = oaTru;
    }

    public void setPi(Nawse pi) {
        this.pi = pi;
    }

    public void setRil(Nawse ril) {
        this.ril = ril;
    }

    public void setNiss(Nawse niss) {
        this.niss = niss;
    }

    public static void husBesmmi(Eldad me, Nawse snu) {
        Nawse liis = new Nawse(640);
        Eldad ar = new Eldad(581);
    }

    public static void ficint() {
        int greo = 45;
        Eldad heu = new Eldad(273);
        int mi = 77;
        HERE;
    }

    public void muol(Eldad wa, Nawse ia, Nawse lism) {
    }

    public static void depfa() {
        Eldad niod = new Eldad(137);
        Nawse oun = new Nawse(733);
        Eldad.imeer(niod, oun);
        oun.muol(niod, oun, new Nawse(414));
    }
}
public class Eldad {
    private int ciss;

    Eldad(int ciss) {
        this.ciss = ciss;
    }

    public static void flod(Eldad tudi, Nawse issu) {
        Nawse.husBesmmi(new Eldad(315), issu);
        issu.setNiss(issu);
        Nawse.ficint();
    }

    public static void imeer(Eldad ve, Nawse clak) {
        Nawse grod = new Nawse(864);
        int ocxe = 77;
        clak.setPi(grod);
        Eldad.flod(ve, clak);
        new Eldad(90).spric();
    }

    public void spric() {
        int re = 77;
        Nawse duoc = new Nawse(158);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: