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


Given the code below, this method call:

Boiss.socro();

...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 Boiss {
    private int ipint;
    private Boiss prar;

    Boiss(int ipint) {
        this.ipint = ipint;
    }

    public void setPrar(Boiss prar) {
        this.prar = prar;
    }

    public static void socro() {
        Boiss ir = new Boiss(753);
        ir.setPrar(ir);
        ir.bopher(ir, new Boiss(837));
    }

    public void bopher(Boiss vork, Boiss ali) {
        ali.pusir(ali, new Boiss(192));
        HERE;
    }

    public void pusir(Boiss ul, Boiss tro) {
    }
}
public class Namiz {
    private int iacci;

    Namiz(int iacci) {
        this.iacci = iacci;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: