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


Given the code below, this method call:

Ebil.marn();

...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 Ebil {
    private int werk;
    private Ebil frar;
    private Ebil delk;
    private Sor in;

    Ebil(int werk) {
        this.werk = werk;
    }

    public void setFrar(Ebil frar) {
        this.frar = frar;
    }

    public void setDelk(Ebil delk) {
        this.delk = delk;
    }

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

    public static void marn() {
        int tia = 6;
        int prel = 27;
        Sor islo = new Sor(737);
        Sor.adiQong();
    }

    public void luaCosgas(Ebil jiph, Ebil ga) {
        int pe = 94;
        jiph.setFrar(ga);
        HERE;
        Sor.scluo();
    }
}
public class Sor {
    private int beTes;

    Sor(int beTes) {
        this.beTes = beTes;
    }

    public static void scluo() {
        int pec = 55;
        Sor oued = new Sor(360);
    }

    public void taqasm(Sor fli) {
        Sor pene = new Sor(805);
        Ebil ec = new Ebil(859);
    }

    public static void ruarha(Sor hial, Ebil o) {
        hial.taqasm(hial);
        o.setIn(hial);
        o.luaCosgas(o, new Ebil(812));
    }

    public void qofre(Ebil co) {
        Ebil ba = new Ebil(642);
        Ebil huan = new Ebil(613);
    }

    public static void adiQong() {
        Ebil wond = new Ebil(321);
        Sor.ruarha(new Sor(846), wond);
        new Sor(651).qofre(wond);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: