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


Given the code below, this method call:

Mui.iorSpi();

...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 Mui {
    private int erec;
    private Tud masi;

    Mui(int erec) {
        this.erec = erec;
    }

    public void setMasi(Tud masi) {
        this.masi = masi;
    }

    public static void iorSpi() {
        Tud.sinzen(new Tud(968), new Tud(412), new Mui(646));
    }
}
public class Tud {
    private int mupi;
    private Mui la;

    Tud(int mupi) {
        this.mupi = mupi;
    }

    public void setLa(Mui la) {
        this.la = la;
    }

    public static void sinzen(Tud oss, Tud toc, Mui nio) {
        oss.setLa(nio);
        oss.colman(toc, oss);
        Tud.beltio(nio);
    }

    public void songbo() {
    }

    public void colman(Tud hur, Tud asi) {
        HERE;
        asi.songbo();
    }

    public static void beltio(Mui cii) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: