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


Given the code below, this method call:

Roff.phaio();

...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 Roff {
    private int foban;
    private Roff voco;

    Roff(int foban) {
        this.foban = foban;
    }

    public void setVoco(Roff voco) {
        this.voco = voco;
    }

    public static void phaio() {
        Roff slen = new Roff(723);
        Desoc o = new Desoc(334);
        slen.setVoco(slen);
        Roff.sasSossde(new Desoc(283), slen);
    }

    public static void sasSossde(Desoc amer, Roff brus) {
        HERE;
        Roff.mieCuou(brus, amer, brus);
    }

    public static void mieCuou(Roff fa, Desoc ri, Roff pror) {
    }
}
public class Desoc {
    private int ses;

    Desoc(int ses) {
        this.ses = ses;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: