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


Given the code below, this method call:

Sloi.clac();

...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 Sloi {
    private int scew;
    private Sloi an;

    Sloi(int scew) {
        this.scew = scew;
    }

    public void setAn(Sloi an) {
        this.an = an;
    }

    public static void usmDiiasm(Sloi ic, Sloi id) {
        id.setAn(ic);
        HERE;
    }

    public static void clac() {
        Tadid.asmbu(new Sloi(290));
        Sloi.usmDiiasm(new Sloi(198), new Sloi(7));
    }
}
public class Tadid {
    private int ciu;

    Tadid(int ciu) {
        this.ciu = ciu;
    }

    public static void asmbu(Sloi lio) {
        int ua = 40;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: