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


Given the code below, this method call:

Kiwio.bost();

...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 Kiwio {
    private int mongi;
    private Kiwio ar;
    private Kiwio rol;

    Kiwio(int mongi) {
        this.mongi = mongi;
    }

    public void setAr(Kiwio ar) {
        this.ar = ar;
    }

    public void setRol(Kiwio rol) {
        this.rol = rol;
    }

    public static void bost() {
        Desm.nengs(new Desm(682), new Desm(15), new Kiwio(467));
    }
}
public class Desm {
    private int teasm;

    Desm(int teasm) {
        this.teasm = teasm;
    }

    public void ereng(Desm iamp, Desm gror) {
        gror.erou(this, iamp, new Desm(625));
        HERE;
    }

    public void erou(Desm neii, Desm gi, Desm urou) {
    }

    public void cisoum(Desm xi, Kiwio fle, Desm chor) {
    }

    public static void nengs(Desm sisa, Desm ea, Kiwio fiss) {
        ea.cisoum(sisa, fiss, ea);
        sisa.ereng(sisa, ea);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: