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


Given the code below, this method call:

Ilbi.zisPoussa();

...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 Ilbi {
    private int maVid;
    private Brir bil;

    Ilbi(int maVid) {
        this.maVid = maVid;
    }

    public void setBil(Brir bil) {
        this.bil = bil;
    }

    public static void fectoc() {
        new Brir(702).fihDiuo(new Ilbi(389), new Brir(789), new Brir(907));
    }

    public static void zisPoussa() {
        Ilbi so = new Ilbi(998);
        int zeaw = 47;
        Ilbi.fectoc();
        Brir.scoih();
    }

    public void launid(Ilbi efa) {
        int ioes = 35;
    }
}
public class Brir {
    private int ungu;
    private Brir bril;

    Brir(int ungu) {
        this.ungu = ungu;
    }

    public void setBril(Brir bril) {
        this.bril = bril;
    }

    public void fihDiuo(Ilbi ecam, Brir eman, Brir al) {
        this.setBril(al);
        HERE;
        ecam.launid(ecam);
    }

    public static void scoih() {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: