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


Given the code below, this method call:

Kri.allior();

...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 Kri {
    private int repha;
    private Bresm ti;
    private Kri ad;

    Kri(int repha) {
        this.repha = repha;
    }

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

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

    public void neun(int nacs) {
        int ciod = 11;
        Bresm kni = new Bresm(292);
        this.setTi(kni);
        kni.rised();
    }

    public void hitmo(Bresm ha) {
    }

    public void ipiOodfli(int nal, Bresm cin, int noer) {
        int pri = 7;
    }

    public static void allior() {
        int trir = 15;
        int is = 69;
        int qa = 65;
        int owon = 39;
        int je = 53;
        new Bresm(404).goftle(je, new Kri(295));
        new Bresm(104).aght();
    }
}
public class Bresm {
    private int hac;
    private Kri en;
    private Bresm cang;

    Bresm(int hac) {
        this.hac = hac;
    }

    public void setEn(Kri en) {
        this.en = en;
    }

    public void setCang(Bresm cang) {
        this.cang = cang;
    }

    public void tosda(Bresm de, Bresm oapi) {
    }

    public void goftle(int bi, Kri bla) {
        new Kri(232).hitmo(this);
    }

    public void aght() {
        Bresm an = new Bresm(164);
        an.setCang(this);
        new Kri(802).neun(71);
        an.tosda(an, this);
    }

    public void rised() {
        int fla = 34;
        int oth = 29;
        Kri gia = new Kri(759);
        Kri ap = new Kri(254);
        ap.setTi(this);
        Bresm.pocvem(oth);
        ap.ipiOodfli(oth, this, fla);
    }

    public static void dentce(int id, int fism, int le) {
    }

    public static void pocvem(int cil) {
        int mio = 27;
        int ool = 48;
        int esan = 77;
        int eljo = 19;
        HERE;
        Bresm.dentce(esan, eljo, mio);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: