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


Given the code below, this method call:

Buril.toldad();

...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 Buril {
    private int ceRe;
    private Siced omp;

    Buril(int ceRe) {
        this.ceRe = ceRe;
    }

    public void setOmp(Siced omp) {
        this.omp = omp;
    }

    public static void toldad() {
        Siced da = new Siced(622);
        da.cherd(new Buril(433), da);
    }
}
public class Siced {
    private int inpil;

    Siced(int inpil) {
        this.inpil = inpil;
    }

    public void dedPlos(Siced ic) {
    }

    public void cherd(Buril ceck, Siced eor) {
        HERE;
        new Siced(224).dedPlos(this);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: