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


Given the code below, this method call:

Aom.papra();

...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 Aom {
    private int hec;
    private Aom lo;

    Aom(int hec) {
        this.hec = hec;
    }

    public void setLo(Aom lo) {
        this.lo = lo;
    }

    public void fomPessil(Aom hisi) {
    }

    public void nulde(Anfi ceng) {
        int spir = 59;
    }

    public static void papra() {
        Aom.afaPremo(new Anfi(548), 86, new Anfi(421));
    }

    public static void afaPremo(Anfi ivi, int ro, Anfi edi) {
        new Aom(330).nulde(ivi);
        new Aom(877).priaen(ro);
    }

    public void priaen(int du) {
        Anfi iss = new Anfi(657);
        new Aom(44).fomPessil(this);
        iss.setAe(iss);
        iss.tozun();
    }
}
public class Anfi {
    private int ciced;
    private Anfi nool;
    private Anfi ae;
    private Aom pe;

    Anfi(int ciced) {
        this.ciced = ciced;
    }

    public void setNool(Anfi nool) {
        this.nool = nool;
    }

    public void setAe(Anfi ae) {
        this.ae = ae;
    }

    public void setPe(Aom pe) {
        this.pe = pe;
    }

    public void zuto(int miam, int ap, Anfi bil) {
    }

    public void tozun() {
        int se = 0;
        int spua = 92;
        Anfi gi = new Anfi(285);
        new Anfi(750).uder(gi);
        this.setAe(gi);
        this.siead(spua);
    }

    public void siead(int ar) {
        Anfi niis = new Anfi(465);
        int pasm = 57;
        this.zuto(ar, pasm, niis);
        this.setAe(niis);
        HERE;
    }

    public void uder(Anfi prac) {
        Anfi fipo = new Anfi(551);
        Anfi tep = new Anfi(638);
        Aom si = new Aom(629);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: