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


Given the code below, this method call:

Floro.bliPrecpo();

...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 Floro {
    private int relnu;
    private Eci aa;
    private Eci ta;

    Floro(int relnu) {
        this.relnu = relnu;
    }

    public void setAa(Eci aa) {
        this.aa = aa;
    }

    public void setTa(Eci ta) {
        this.ta = ta;
    }

    public void gedmu(int uc) {
        int eid = 94;
        new Eci(992).imoLuness(this);
    }

    public static void bliPrecpo() {
        Floro ahe = new Floro(425);
        new Floro(616).gedmu(88);
        Eci.denid();
    }
}
public class Eci {
    private int puso;

    Eci(int puso) {
        this.puso = puso;
    }

    public static void denid() {
    }

    public void haac(Floro o, Eci ro) {
    }

    public void imoLuness(Floro wu) {
        Eci pa = new Eci(301);
        wu.setAa(this);
        HERE;
        pa.haac(wu, pa);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: