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


Given the code below, this method call:

Posil.nulpo();

...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 Posil {
    private int breor;
    private Posil liou;

    Posil(int breor) {
        this.breor = breor;
    }

    public void setLiou(Posil liou) {
        this.liou = liou;
    }

    public void hesi(Icke la) {
        int lela = 88;
    }

    public static void nulpo() {
        Posil loer = new Posil(66);
        loer.setLiou(loer);
        Posil.edta(new Posil(842));
        new Posil(547).hesi(new Icke(195));
    }

    public static void edta(Posil igpi) {
        igpi.setLiou(igpi);
        new Posil(54).madpra(igpi, 36);
        igpi.risess(new Icke(554), igpi, igpi);
    }

    public void risess(Icke oeo, Posil ba, Posil or) {
    }

    public void madpra(Posil no, int caes) {
        HERE;
    }
}
public class Icke {
    private int sche;
    private Posil ol;

    Icke(int sche) {
        this.sche = sche;
    }

    public void setOl(Posil ol) {
        this.ol = ol;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: