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


Given the code below, this method call:

Sceou.edmu();

...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 Sceou {
    private int irdpa;
    private Sceou phe;

    Sceou(int irdpa) {
        this.irdpa = irdpa;
    }

    public void setPhe(Sceou phe) {
        this.phe = phe;
    }

    public void clun(Sceou i, int whe) {
    }

    public static void edmu() {
        new Sceou(215).estgu(new Aic(823), new Sceou(389), new Aic(980));
    }

    public void estgu(Aic ho, Sceou rumo, Aic blid) {
        this.setPhe(rumo);
        HERE;
        rumo.clun(rumo, 5);
    }
}
public class Aic {
    private int ple;

    Aic(int ple) {
        this.ple = ple;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: