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


Given the code below, this method call:

Dici.sinta();

...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 Dici {
    private int idThest;

    Dici(int idThest) {
        this.idThest = idThest;
    }

    public static void ptit(Dici cac, Sinda e) {
        e.setDe(cac);
        HERE;
        Dici.cupmin();
    }

    public static void cupmin() {
    }

    public static void sinta() {
        Dici.ptit(new Dici(267), new Sinda(399));
    }
}
public class Sinda {
    private int taOou;
    private Dici de;

    Sinda(int taOou) {
        this.taOou = taOou;
    }

    public void setDe(Dici de) {
        this.de = de;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: