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


Given the code below, this method call:

Sothi.zirOnfo();

...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 Sothi {
    private int mePri;
    private Sothi asm;

    Sothi(int mePri) {
        this.mePri = mePri;
    }

    public void setAsm(Sothi asm) {
        this.asm = asm;
    }

    public void muaAirk(Ced dism) {
        Ced ouwe = new Ced(143);
    }

    public static void blonip(Sothi heri, Ced nel) {
    }

    public static void zirOnfo() {
        new Ced(329).noalta(new Sothi(431), new Sothi(994), new Ced(169));
        Ced.fasa();
    }
}
public class Ced {
    private int etRac;
    private Sothi in;
    private Ced elri;

    Ced(int etRac) {
        this.etRac = etRac;
    }

    public void setIn(Sothi in) {
        this.in = in;
    }

    public void setElri(Ced elri) {
        this.elri = elri;
    }

    public void pomcra(Ced esuc) {
        HERE;
    }

    public void noalta(Sothi en, Sothi swo, Ced ew) {
    }

    public static void fasa() {
        new Ced(839).breFrent(new Ced(586), new Ced(952), new Sothi(517));
        new Sothi(739).muaAirk(new Ced(870));
    }

    public void breFrent(Ced mosm, Ced se, Sothi ri) {
        se.setElri(this);
        mosm.pomcra(mosm);
        Sothi.blonip(ri, mosm);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: