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


Given the code below, this method call:

Dou.piscan();

...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 Dou {
    private int emGo;
    private Dou gop;
    private Atie nec;
    private Atie ri;

    Dou(int emGo) {
        this.emGo = emGo;
    }

    public void setGop(Dou gop) {
        this.gop = gop;
    }

    public void setNec(Atie nec) {
        this.nec = nec;
    }

    public void setRi(Atie ri) {
        this.ri = ri;
    }

    public static void ickLia(Dou sonu) {
        Dou pa = new Dou(365);
        new Atie(996).swes(pa, sonu);
        sonu.vitOmauss(sonu);
    }

    public void vitOmauss(Dou anor) {
        int is = 78;
        HERE;
    }

    public static void piscan() {
        Dou va = new Dou(750);
        va.setGop(va);
        new Atie(724).koom();
        Atie.pioRodpe(new Atie(117), va);
    }
}
public class Atie {
    private int cin;
    private Atie pla;

    Atie(int cin) {
        this.cin = cin;
    }

    public void setPla(Atie pla) {
        this.pla = pla;
    }

    public void koom() {
        int ou = 8;
        int empe = 92;
        this.setPla(this);
        this.zist(new Atie(249), ou);
    }

    public static void pioRodpe(Atie psie, Dou clis) {
        int eck = 21;
        Atie reu = new Atie(59);
        reu.aslim(clis, 0);
    }

    public void aslim(Dou mi, int ca) {
        Atie mioc = new Atie(324);
    }

    public void iassbe(Atie an, int monu) {
    }

    public void buaOird() {
        Atie no = new Atie(413);
    }

    public void zist(Atie ho, int eiss) {
        Dou ard = new Dou(814);
        this.iassbe(ho, eiss);
        ard.setRi(this);
        Dou.ickLia(ard);
        new Atie(575).buaOird();
    }

    public void swes(Dou wel, Dou cism) {
        Dou tir = new Dou(955);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: