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


Given the code below, this method call:

Bocas.oucPrur();

...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 Bocas {
    private int cink;
    private Bocas blod;
    private Osir or;

    Bocas(int cink) {
        this.cink = cink;
    }

    public void setBlod(Bocas blod) {
        this.blod = blod;
    }

    public void setOr(Osir or) {
        this.or = or;
    }

    public void gneTian(Bocas ji, Bocas spim) {
    }

    public static void oucPrur() {
        int thec = 10;
        new Bocas(754).ecger(new Bocas(335));
    }

    public static void cinCeris() {
        int tusa = 48;
    }

    public void ecger(Bocas ar) {
        Bocas onde = new Bocas(3);
        this.thande();
        new Bocas(240).gneTian(onde, new Bocas(114));
    }

    public void thande() {
        Bocas.cinCeris();
        this.setBlod(this);
        HERE;
    }
}
public class Osir {
    private int whi;

    Osir(int whi) {
        this.whi = whi;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: