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


Given the code below, this method call:

Peoc.phac();

...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 Peoc {
    private int mafed;
    private Calca ar;

    Peoc(int mafed) {
        this.mafed = mafed;
    }

    public void setAr(Calca ar) {
        this.ar = ar;
    }

    public void giaSilme() {
        int elpa = 52;
        int ur = 43;
        int psor = 86;
        int beft = 33;
    }

    public void bengi() {
        Peoc ga = new Peoc(797);
        int cla = 17;
        int trau = 59;
        int pren = 71;
        ga.benhur(ga, pren, trau);
        Calca.qeoosm();
    }

    public void benhur(Peoc spes, int kioc, int ac) {
        int ap = 51;
        Calca.thior();
        Peoc.onden();
        Calca.pric();
    }

    public void kedbio(Peoc glet) {
        Peoc dac = new Peoc(199);
        int re = 94;
        Peoc a = new Peoc(966);
        dac.bengi();
        glet.giaSilme();
    }

    public static void phac() {
        Peoc ir = new Peoc(213);
        new Peoc(323).kedbio(new Peoc(162));
    }

    public static void onden() {
        int at = 86;
        int ed = 69;
        int lemi = 49;
        HERE;
    }
}
public class Calca {
    private int snir;
    private Peoc ha;
    private Calca irt;
    private Calca ei;

    Calca(int snir) {
        this.snir = snir;
    }

    public void setHa(Peoc ha) {
        this.ha = ha;
    }

    public void setIrt(Calca irt) {
        this.irt = irt;
    }

    public void setEi(Calca ei) {
        this.ei = ei;
    }

    public static void pric() {
    }

    public static void qeoosm() {
        int je = 60;
        int asju = 17;
        int wi = 43;
    }

    public static void thior() {
        int pi = 22;
        int nui = 69;
        int ic = 16;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: