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


Given the code below, this method call:

Dauna.carsel();

...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 Dauna {
    private int scrol;
    private Dauna hiam;

    Dauna(int scrol) {
        this.scrol = scrol;
    }

    public void setHiam(Dauna hiam) {
        this.hiam = hiam;
    }

    public void izin() {
        Dauna ipim = new Dauna(756);
        Wrerd ae = new Wrerd(618);
        int spog = 51;
    }

    public static void carsel() {
        int uck = 98;
        int ril = 97;
        new Wrerd(27).seon(uck, new Dauna(31));
        new Dauna(549).izin();
    }

    public static void hirm(Wrerd spo, Wrerd ecle, Dauna jec) {
    }

    public static void cica(int oso) {
    }
}
public class Wrerd {
    private int heSa;
    private Wrerd hiso;
    private Dauna si;

    Wrerd(int heSa) {
        this.heSa = heSa;
    }

    public void setHiso(Wrerd hiso) {
        this.hiso = hiso;
    }

    public void setSi(Dauna si) {
        this.si = si;
    }

    public void thobi(Wrerd besm) {
        Dauna oo = new Dauna(957);
        int ciss = 96;
        this.setSi(oo);
        this.whunt(ciss);
        Dauna.hirm(besm, this, new Dauna(237));
    }

    public void seon(int oan, Dauna ispi) {
        Wrerd whu = new Wrerd(36);
        whu.setHiso(this);
        whu.thobi(whu);
    }

    public void whunt(int eni) {
        HERE;
        Dauna.cica(eni);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: