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


Given the code below, this method call:

Elfap.antlu();

...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 Elfap {
    private int namgu;

    Elfap(int namgu) {
        this.namgu = namgu;
    }

    public void esaChist(Ubir dast, Ubir ded) {
        Ubir.uadIss(dast, this, ded);
        dast.setAp(ded);
        HERE;
    }

    public static void antlu() {
        new Elfap(453).esaChist(new Ubir(531), new Ubir(360));
    }
}
public class Ubir {
    private int hil;
    private Ubir ap;

    Ubir(int hil) {
        this.hil = hil;
    }

    public void setAp(Ubir ap) {
        this.ap = ap;
    }

    public static void uadIss(Ubir bre, Elfap euft, Ubir eces) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: