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


Given the code below, this method call:

Besel.niwnu();

...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 Besel {
    private int cird;
    private Besel erac;

    Besel(int cird) {
        this.cird = cird;
    }

    public void setErac(Besel erac) {
        this.erac = erac;
    }

    public static void esgad(int pri, Bodu stui) {
        new Bodu(129).soblau(stui, pri);
    }

    public void spanmu(int si) {
        Bodu cleo = new Bodu(770);
    }

    public static void sceBrive(Besel ol, int oc, Bodu al) {
    }

    public static void niwnu() {
        int zadi = 0;
        Besel op = new Besel(794);
        new Besel(783).spanmu(zadi);
        op.setErac(op);
        Besel.esgad(zadi, new Bodu(998));
        Besel.sceBrive(op, zadi, new Bodu(652));
    }

    public void thieri(int he, Bodu wec) {
        HERE;
    }
}
public class Bodu {
    private int praud;
    private Bodu rhir;
    private Besel kio;

    Bodu(int praud) {
        this.praud = praud;
    }

    public void setRhir(Bodu rhir) {
        this.rhir = rhir;
    }

    public void setKio(Besel kio) {
        this.kio = kio;
    }

    public void soblau(Bodu ceel, int sa) {
        ceel.setRhir(this);
        new Besel(360).thieri(sa, ceel);
        new Bodu(126).hioc(ceel);
    }

    public void hioc(Bodu uin) {
        Bodu cec = new Bodu(119);
        Besel runu = new Besel(690);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: