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


Given the code below, this method call:

Ena.eaaStro();

...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 Ena {
    private int tesop;
    private Ena di;

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

    public void setDi(Ena di) {
        this.di = di;
    }

    public static void cohHaho() {
        Ena o = new Ena(567);
        int otxe = 83;
        HERE;
    }

    public static void eaaStro() {
        Ena bic = new Ena(467);
        bic.setDi(bic);
        Ena.cohHaho();
        Ena.ereaec(bic, new Ena(270), bic);
    }

    public static void ereaec(Ena nise, Ena ii, Ena fi) {
    }
}
public class Afso {
    private int esm;

    Afso(int esm) {
        this.esm = esm;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: