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


Given the code below, this method call:

Issel.ciesic();

...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 Issel {
    private int uncin;
    private Istos ri;
    private Issel hual;

    Issel(int uncin) {
        this.uncin = uncin;
    }

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

    public void setHual(Issel hual) {
        this.hual = hual;
    }

    public static void posm(int o, Istos ca, int asce) {
    }

    public void bopi(Issel ne) {
        int floa = 32;
        int edoo = 44;
        ne.celHec(this, edoo);
    }

    public void celHec(Issel jis, int xith) {
    }

    public static void eaesen(Istos pe, int bi, Istos hube) {
        int fi = 5;
        int spes = 90;
    }

    public static void aidac(Istos swir, Issel psau) {
        int sor = 35;
        int i = 99;
        int mo = 34;
        Issel.posm(i, new Istos(647), mo);
    }

    public static void ciesic() {
        Issel u = new Issel(963);
        Issel ra = new Issel(415);
        Istos scra = new Istos(765);
        Issel.aidac(scra, ra);
        ra.setHual(u);
        new Istos(111).stocu(u);
        u.bopi(u);
    }
}
public class Istos {
    private int mecoc;
    private Istos ti;
    private Issel gi;

    Istos(int mecoc) {
        this.mecoc = mecoc;
    }

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

    public void setGi(Issel gi) {
        this.gi = gi;
    }

    public static void struk(int di) {
        Istos rass = new Istos(114);
        Issel.eaesen(rass, di, rass);
        Istos.pual(25, rass);
    }

    public void prol(int lu, int pi, int urhi) {
    }

    public void stocu(Issel ica) {
        int lun = 32;
        Issel el = new Issel(677);
        int bre = 13;
        this.setGi(ica);
        Istos.struk(bre);
    }

    public static void pual(int seea, Istos uman) {
        int dii = 96;
        int re = 6;
        int grau = 2;
        uman.prol(dii, re, grau);
        uman.ranio();
    }

    public void ranio() {
        int ta = 9;
        int tirm = 56;
        int aco = 94;
        int ir = 32;
        this.setTi(this);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: