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


Given the code below, this method call:

Ses.prel();

...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 Ses {
    private int uson;

    Ses(int uson) {
        this.uson = uson;
    }

    public void mecia(Ucsa ge, Ucsa he) {
        new Ses(964).rerBufess();
        ge.setSeng(this);
        HERE;
    }

    public static void prel() {
        Ucsa.harGror(new Ucsa(925), new Ses(614));
    }

    public void rerBufess() {
    }
}
public class Ucsa {
    private int tred;
    private Ucsa er;
    private Ses seng;

    Ucsa(int tred) {
        this.tred = tred;
    }

    public void setEr(Ucsa er) {
        this.er = er;
    }

    public void setSeng(Ses seng) {
        this.seng = seng;
    }

    public static void harGror(Ucsa be, Ses sa) {
        new Ucsa(867).bied(be, new Ucsa(512), sa);
        be.setSeng(sa);
        sa.mecia(be, new Ucsa(902));
    }

    public void bied(Ucsa ci, Ucsa erud, Ses or) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: