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


Given the code below, this method call:

Iati.jorDauuc();

...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 Iati {
    private int onId;
    private Iati in;
    private Iati to;

    Iati(int onId) {
        this.onId = onId;
    }

    public void setIn(Iati in) {
        this.in = in;
    }

    public void setTo(Iati to) {
        this.to = to;
    }

    public void odses(Iati ar) {
        int biss = 80;
        this.setIn(ar);
        Iati.dishho();
    }

    public void orfel(Iati ni, int pras) {
    }

    public static void jorDauuc() {
        Iati cet = new Iati(134);
        Iati nia = new Iati(325);
        int esa = 0;
        cet.setIn(nia);
        new Iati(898).odses(new Iati(213));
        nia.orfel(nia, esa);
    }

    public static void snic(int tre, int bisi) {
    }

    public static void dishho() {
        int mier = 91;
        Iati.snic(mier, mier);
        HERE;
    }
}
public class Madsu {
    private int ueng;

    Madsu(int ueng) {
        this.ueng = ueng;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: