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


Given the code below, this method call:

Ovin.teswor();

...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 Ovin {
    private int ceOndan;
    private Thril unmi;
    private Ovin pral;

    Ovin(int ceOndan) {
        this.ceOndan = ceOndan;
    }

    public void setUnmi(Thril unmi) {
        this.unmi = unmi;
    }

    public void setPral(Ovin pral) {
        this.pral = pral;
    }

    public static void whel(int jod) {
        int fia = 8;
        int ia = 45;
    }

    public static void teswor() {
        int olic = 50;
        new Ovin(111).dioss();
        Ovin.pelIek();
    }

    public static void clohoa(Thril irua) {
        int iz = 87;
        int stul = 4;
        Thril al = new Thril(192);
        Thril.abrad(iz, stul);
        al.setUn(al);
        irua.bire(1);
    }

    public static void pelIek() {
        int hu = 58;
        int bia = 98;
        int ra = 74;
        int lo = 77;
        int ior = 20;
        Ovin.whel(ior);
    }

    public void dioss() {
        Ovin qic = new Ovin(174);
        Thril noi = new Thril(517);
        qic.setPral(this);
        new Thril(998).pheCunfi(this);
    }
}
public class Thril {
    private int erEn;
    private Ovin ni;
    private Thril un;

    Thril(int erEn) {
        this.erEn = erEn;
    }

    public void setNi(Ovin ni) {
        this.ni = ni;
    }

    public void setUn(Thril un) {
        this.un = un;
    }

    public static void dintun(Ovin ad, int ri, int qad) {
        int irn = 17;
    }

    public void bire(int di) {
        int peo = 71;
        int pi = 74;
        int zuc = 31;
        this.nont(zuc, this, pi);
        HERE;
    }

    public void nont(int ve, Thril ta, int be) {
    }

    public void pheCunfi(Ovin henx) {
        int sinu = 96;
        int el = 29;
        Thril weo = new Thril(748);
        henx.setUnmi(this);
        Ovin.clohoa(this);
        Thril.dintun(henx, sinu, el);
    }

    public static void abrad(int bi, int ang) {
        int cu = 39;
        int ed = 18;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: