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


Given the code below, this method call:

Scen.lieng();

...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 Scen {
    private int anAc;
    private Aoil ste;
    private Aoil fasm;

    Scen(int anAc) {
        this.anAc = anAc;
    }

    public void setSte(Aoil ste) {
        this.ste = ste;
    }

    public void setFasm(Aoil fasm) {
        this.fasm = fasm;
    }

    public static void lieng() {
        Aoil pler = new Aoil(169);
        Aoil.tral();
        pler.setIc(pler);
        pler.prer(pler, new Scen(177), 17);
    }

    public void dissci(Aoil pa) {
        int pior = 51;
        int shic = 22;
    }

    public static void ihos() {
        Aoil oas = new Aoil(727);
        Aoil.opast(oas, 65);
        HERE;
    }

    public static void eisPle(Scen au) {
        Scen beos = new Scen(460);
        Aoil er = new Aoil(189);
        Aoil ie = new Aoil(177);
        Scen a = new Scen(105);
    }
}
public class Aoil {
    private int erant;
    private Aoil ic;
    private Scen viar;

    Aoil(int erant) {
        this.erant = erant;
    }

    public void setIc(Aoil ic) {
        this.ic = ic;
    }

    public void setViar(Scen viar) {
        this.viar = viar;
    }

    public static void tral() {
        Scen ta = new Scen(21);
        Scen.eisPle(ta);
    }

    public void prer(Aoil ho, Scen agne, int pei) {
        int caou = 50;
        ho.setViar(agne);
        Aoil.ficse(new Scen(224), pei, agne);
        ho.tianu(ho, pei, this);
    }

    public static void teeght() {
        Aoil qing = new Aoil(35);
        int ec = 9;
        Scen.ihos();
    }

    public static void opast(Aoil clis, int kri) {
    }

    public static void ficse(Scen pruc, int am, Scen us) {
        int iag = 78;
        Aoil ege = new Aoil(362);
        us.setFasm(ege);
        Aoil.teeght();
        us.dissci(ege);
    }

    public void tianu(Aoil spe, int cu, Aoil onur) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: