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


Given the code below, this method call:

Erad.nandol();

...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 Erad {
    private int ioPe;
    private Sto alel;

    Erad(int ioPe) {
        this.ioPe = ioPe;
    }

    public void setAlel(Sto alel) {
        this.alel = alel;
    }

    public static void cacga(int o, int oc, int pige) {
        int er = 37;
        Erad.hoacis();
    }

    public static void dugrir(int pou, Sto ea) {
        int ceme = 6;
    }

    public static void kisspe() {
        Sto fuc = new Sto(945);
        fuc.setPloc(fuc);
        Erad.zasPse(new Sto(395));
        fuc.fepnad(fuc, fuc);
    }

    public static void zasPse(Sto uss) {
        uss.pult(new Erad(99));
    }

    public static void hoacis() {
        int ha = 33;
        int alde = 87;
        int adko = 11;
        int is = 55;
    }

    public static void nandol() {
        int tac = 32;
        int ugs = 24;
        int ston = 29;
        Erad rac = new Erad(605);
        Sto a = new Sto(626);
        new Erad(63).ehaSul(ugs, ston);
        rac.setAlel(a);
        Erad.kisspe();
        Erad.cacga(tac, ston, ugs);
    }

    public void ehaSul(int rott, int esbi) {
        new Sto(796).schowu();
    }
}
public class Sto {
    private int brec;
    private Sto ploc;
    private Erad oss;
    private Erad aje;

    Sto(int brec) {
        this.brec = brec;
    }

    public void setPloc(Sto ploc) {
        this.ploc = ploc;
    }

    public void setOss(Erad oss) {
        this.oss = oss;
    }

    public void setAje(Erad aje) {
        this.aje = aje;
    }

    public void fepnad(Sto ieou, Sto te) {
    }

    public void pult(Erad os) {
        Sto cas = new Sto(958);
        int spen = 58;
        Erad.dugrir(spen, cas);
        this.setAje(os);
        this.cucpu(spen);
    }

    public void cucpu(int es) {
        HERE;
    }

    public void schowu() {
        int vul = 54;
        int deng = 55;
        Erad co = new Erad(283);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: