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


Given the code below, this method call:

Suve.daca();

...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 Suve {
    private int kude;
    private Suve ae;

    Suve(int kude) {
        this.kude = kude;
    }

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

    public void fres(Suve pism) {
        int e = 43;
        int te = 63;
    }

    public static void briEcsia(Suve ec) {
        int afod = 17;
    }

    public void thux() {
        int eid = 94;
    }

    public void hiadio(int al, int es) {
        int ie = 15;
    }

    public static void daca() {
        int uc = 82;
        Suve gri = new Suve(204);
        int em = 95;
        gri.setAe(gri);
        gri.pisie(92, uc, em);
    }

    public void fleArnul(Sebon orel) {
        int deoc = 77;
        Suve.briEcsia(this);
        Sebon.bilsa(deoc, orel, this);
        this.thux();
    }

    public void pisie(int iss, int pe, int meis) {
        Sebon ca = new Sebon(673);
        ca.setOu(this);
        Sebon.recko(pe, meis, iss);
        this.hiadio(iss, 4);
    }
}
public class Sebon {
    private int inUtoc;
    private Suve ad;
    private Sebon ti;
    private Suve ou;

    Sebon(int inUtoc) {
        this.inUtoc = inUtoc;
    }

    public void setAd(Suve ad) {
        this.ad = ad;
    }

    public void setTi(Sebon ti) {
        this.ti = ti;
    }

    public void setOu(Suve ou) {
        this.ou = ou;
    }

    public static void recko(int cebe, int oa, int ic) {
        Suve ool = new Suve(106);
        Suve tren = new Suve(310);
        ool.setAe(tren);
        new Suve(560).fleArnul(new Sebon(189));
        ool.fres(tren);
    }

    public static void bilsa(int ed, Sebon pi, Suve mesm) {
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: