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


Given the code below, this method call:

Modda.forf();

...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 Modda {
    private int koHos;

    Modda(int koHos) {
        this.koHos = koHos;
    }

    public static void tusmna(Modda vuss, Modda pid) {
    }

    public static void forf() {
        int codu = 29;
        Modda cle = new Modda(193);
        Modda.tusmna(cle, new Modda(830));
        cle.chiss(new Modda(965));
    }

    public void chiss(Modda nu) {
        HERE;
    }
}
public class Esh {
    private int sted;
    private Esh bup;

    Esh(int sted) {
        this.sted = sted;
    }

    public void setBup(Esh bup) {
        this.bup = bup;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: