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


Given the code below, this method call:

Epoc.brai();

...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 Epoc {
    private int daMi;
    private Uscac ang;

    Epoc(int daMi) {
        this.daMi = daMi;
    }

    public void setAng(Uscac ang) {
        this.ang = ang;
    }

    public static void qundin() {
        int dece = 80;
        int asm = 1;
    }

    public static void brai() {
        Epoc ca = new Epoc(288);
        Epoc wai = new Epoc(657);
        Uscac tia = new Uscac(150);
        Epoc se = new Epoc(173);
        new Uscac(329).tosved(se, ca, new Epoc(751));
        wai.setAng(tia);
        new Uscac(988).peple(se, new Epoc(372), tia);
    }

    public void enoJallir(Epoc ste, Epoc em) {
        int is = 71;
    }

    public void nasso() {
        int broc = 29;
        Uscac.oegCawpru(broc);
        Uscac.feochi(broc);
    }
}
public class Uscac {
    private int thran;
    private Uscac qor;
    private Uscac iune;
    private Uscac ungo;

    Uscac(int thran) {
        this.thran = thran;
    }

    public void setQor(Uscac qor) {
        this.qor = qor;
    }

    public void setIune(Uscac iune) {
        this.iune = iune;
    }

    public void setUngo(Uscac ungo) {
        this.ungo = ungo;
    }

    public void peple(Epoc hi, Epoc neco, Uscac po) {
        this.setQor(po);
        neco.nasso();
        this.ormArsol();
    }

    public void ormArsol() {
    }

    public static void colhoi(int shre, int oc) {
        int morm = 31;
        int rini = 39;
        Epoc.qundin();
        HERE;
    }

    public void tosved(Epoc pa, Epoc ar, Epoc e) {
        Uscac eosa = new Uscac(590);
        ar.enoJallir(new Epoc(29), ar);
    }

    public static void feochi(int ma) {
        int ini = 2;
        int re = 85;
        int erod = 50;
        int beil = 73;
        Uscac.colhoi(ini, re);
    }

    public static void oegCawpru(int upa) {
        int vooc = 5;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: