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


Given the code below, this method call:

Plost.hiou();

...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 Plost {
    private int suAnri;

    Plost(int suAnri) {
        this.suAnri = suAnri;
    }

    public static void hiou() {
        Daipe fiol = new Daipe(791);
        Daipe.erpos(fiol, new Plost(312));
    }
}
public class Daipe {
    private int siRer;
    private Plost oo;

    Daipe(int siRer) {
        this.siRer = siRer;
    }

    public void setOo(Plost oo) {
        this.oo = oo;
    }

    public void ossBacpe(Plost eh, Plost be, Daipe po) {
    }

    public static void erpos(Daipe ca, Plost fo) {
        ca.setOo(fo);
        HERE;
        new Daipe(961).ossBacpe(fo, new Plost(956), ca);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: