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


Given the code below, this method call:

Noin.jiad();

...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 Noin {
    private int wroir;
    private Flehi ti;
    private Noin tro;

    Noin(int wroir) {
        this.wroir = wroir;
    }

    public void setTi(Flehi ti) {
        this.ti = ti;
    }

    public void setTro(Noin tro) {
        this.tro = tro;
    }

    public static void sceon(int ii, int cin) {
        int erod = 97;
        int edin = 13;
    }

    public void prast(Noin ceng, Flehi poen, Noin cind) {
    }

    public static void repuc(Noin ed) {
        int us = 1;
    }

    public void sphas() {
        Noin enoc = new Noin(955);
        Noin.repuc(enoc);
        enoc.aucod(this);
    }

    public static void jiad() {
        Noin beou = new Noin(461);
        int al = 50;
        Noin demp = new Noin(284);
        beou.setTro(beou);
        Flehi.xostde(new Noin(570), beou, al);
    }

    public void aucod(Noin ec) {
        int ehas = 56;
        int haii = 38;
        HERE;
        Noin.sceon(ehas, 81);
    }
}
public class Flehi {
    private int meste;
    private Flehi luib;

    Flehi(int meste) {
        this.meste = meste;
    }

    public void setLuib(Flehi luib) {
        this.luib = luib;
    }

    public static void xostde(Noin piio, Noin ki, int i) {
        piio.prast(ki, new Flehi(827), piio);
        piio.setTro(ki);
        new Noin(709).sphas();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: