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


Given the code below, this method call:

Aou.qard();

...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 Aou {
    private int ontex;
    private Aou kec;
    private Sape stip;
    private Sape sto;

    Aou(int ontex) {
        this.ontex = ontex;
    }

    public void setKec(Aou kec) {
        this.kec = kec;
    }

    public void setStip(Sape stip) {
        this.stip = stip;
    }

    public void setSto(Sape sto) {
        this.sto = sto;
    }

    public void sasm() {
        int thic = 74;
        int uss = 54;
        int ap = 76;
        Aou.tessbe(thic);
        Aou.tontga(ap);
    }

    public static void tontga(int qerd) {
    }

    public static void tessbe(int deid) {
        int sede = 56;
        int phor = 12;
        Sape.kacop(sede, phor, deid);
        HERE;
    }

    public static void qard() {
        Sape oul = new Sape(865);
        Sape ni = new Sape(944);
        Aou jiot = new Aou(155);
        jiot.setSto(ni);
        Sape.cisu();
        ni.lonmac(ni, oul, jiot);
    }
}
public class Sape {
    private int hasat;
    private Sape at;

    Sape(int hasat) {
        this.hasat = hasat;
    }

    public void setAt(Sape at) {
        this.at = at;
    }

    public static void kacop(int iss, int bedo, int tru) {
        int plom = 67;
        int eaec = 74;
    }

    public static void colda() {
        int psu = 99;
    }

    public static void cisu() {
        Aou nish = new Aou(40);
        int ded = 96;
        Sape gle = new Sape(442);
        int ond = 17;
        Sape odpe = new Sape(12);
        gle.setAt(odpe);
        Sape.olfarm(gle, nish, ded);
    }

    public void lonmac(Sape chir, Sape ces, Aou pra) {
        ces.epin(pra, chir);
    }

    public void epin(Aou friu, Sape obri) {
        int ceum = 16;
    }

    public static void olfarm(Sape voa, Aou uc, int knad) {
        int ir = 80;
        Sape.colda();
        voa.setAt(voa);
        uc.sasm();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: