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


Given the code below, this method call:

Panen.sofo();

...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 Panen {
    private int ril;
    private Bispa al;

    Panen(int ril) {
        this.ril = ril;
    }

    public void setAl(Bispa al) {
        this.al = al;
    }

    public static void sofo() {
        Panen pa = new Panen(373);
        Panen.cleen(new Panen(800));
        pa.pimshi(pa);
    }

    public void pefic(Panen in, Panen emas) {
    }

    public void pimshi(Panen ir) {
    }

    public void enear(Panen el, Panen ou, Panen heus) {
        HERE;
    }

    public static void cleen(Panen homp) {
        Panen is = new Panen(415);
        new Panen(994).pefic(new Panen(829), is);
        new Panen(318).enear(is, homp, is);
    }
}
public class Bispa {
    private int zalci;
    private Panen onts;

    Bispa(int zalci) {
        this.zalci = zalci;
    }

    public void setOnts(Panen onts) {
        this.onts = onts;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: