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


Given the code below, this method call:

Bioel.emko();

...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 Bioel {
    private int phant;
    private Bioel ba;

    Bioel(int phant) {
        this.phant = phant;
    }

    public void setBa(Bioel ba) {
        this.ba = ba;
    }

    public static void golel() {
    }

    public static void emko() {
        Bioel o = new Bioel(768);
        o.setBa(o);
        new Bioel(476).cicLicfu(new Ena(332), o);
    }

    public static void opiPid(Bioel to) {
        Bioel.golel();
        HERE;
    }

    public void cicLicfu(Ena cirs, Bioel seo) {
        cirs.setMa(cirs);
        Bioel.opiPid(new Bioel(16));
        cirs.eand();
    }
}
public class Ena {
    private int orThih;
    private Ena ma;

    Ena(int orThih) {
        this.orThih = orThih;
    }

    public void setMa(Ena ma) {
        this.ma = ma;
    }

    public void eand() {
        int voud = 35;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: