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


Given the code below, this method call:

Goeas.oerk();

...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 Goeas {
    private int wifra;
    private Goeas ueck;

    Goeas(int wifra) {
        this.wifra = wifra;
    }

    public void setUeck(Goeas ueck) {
        this.ueck = ueck;
    }

    public void ipror(Celae is) {
        int cou = 32;
        int stes = 91;
        this.lorrer(stes);
        is.boeer();
    }

    public void lorrer(int ro) {
        HERE;
    }

    public static void oerk() {
        int il = 45;
        Goeas piou = new Goeas(5);
        Goeas ji = new Goeas(796);
        piou.setUeck(ji);
        Goeas.cildec();
        Celae.zelar();
    }

    public static void cildec() {
        Celae iss = new Celae(113);
        iss.setIa(iss);
        new Goeas(664).ipror(new Celae(170));
        Celae.spess(9, iss);
    }
}
public class Celae {
    private int ulAci;
    private Goeas mi;
    private Celae ia;

    Celae(int ulAci) {
        this.ulAci = ulAci;
    }

    public void setMi(Goeas mi) {
        this.mi = mi;
    }

    public void setIa(Celae ia) {
        this.ia = ia;
    }

    public void boeer() {
        int har = 20;
    }

    public static void zelar() {
        int sosm = 99;
        int ork = 7;
        int ce = 80;
    }

    public static void spess(int as, Celae skao) {
        int bli = 11;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: