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


Given the code below, this method call:

Eha.ealsi();

...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 Eha {
    private int tiPren;
    private Flok te;

    Eha(int tiPren) {
        this.tiPren = tiPren;
    }

    public void setTe(Flok te) {
        this.te = te;
    }

    public static void iasSisem(int esoo) {
        Eha cruc = new Eha(980);
        new Eha(889).gimfra(esoo, cruc);
        Flok.mard(cruc);
    }

    public static void ealsi() {
        Eha deri = new Eha(871);
        int khid = 5;
        Eha mu = new Eha(769);
        new Flok(337).cislud(mu, new Flok(436));
        Eha.iasSisem(khid);
    }

    public void gimfra(int iic, Eha tuss) {
        HERE;
    }
}
public class Flok {
    private int loEl;
    private Eha fa;

    Flok(int loEl) {
        this.loEl = loEl;
    }

    public void setFa(Eha fa) {
        this.fa = fa;
    }

    public void cislud(Eha ple, Flok ur) {
    }

    public static void mard(Eha scra) {
        int su = 42;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: