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


Given the code below, this method call:

Ucna.geos();

...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 Ucna {
    private int osa;
    private Ucna tru;
    private Caceg ois;

    Ucna(int osa) {
        this.osa = osa;
    }

    public void setTru(Ucna tru) {
        this.tru = tru;
    }

    public void setOis(Caceg ois) {
        this.ois = ois;
    }

    public static void geos() {
        Caceg cri = new Caceg(643);
        Caceg fes = new Caceg(61);
        Caceg abra = new Caceg(438);
        Ucna.knio();
        fes.seda();
    }

    public static void osso(int oces, int pimo) {
        int tio = 57;
        int ial = 59;
        int rosm = 51;
    }

    public static void knio() {
        int ourb = 62;
        int mef = 54;
        Caceg ine = new Caceg(148);
        Caceg.ponk(ine);
    }
}
public class Caceg {
    private int anwa;
    private Ucna pton;
    private Ucna fle;

    Caceg(int anwa) {
        this.anwa = anwa;
    }

    public void setPton(Ucna pton) {
        this.pton = pton;
    }

    public void setFle(Ucna fle) {
        this.fle = fle;
    }

    public void preli(Caceg papo, int la) {
        int ai = 32;
        int trud = 74;
    }

    public static void geup(int snol) {
        int bli = 27;
        int haur = 23;
    }

    public static void bross(int ud) {
        int pimi = 11;
        Caceg.geup(pimi);
        HERE;
        Caceg.nicse(pimi, ud);
    }

    public static void ponk(Caceg rhid) {
        Ucna fi = new Ucna(372);
        Caceg mo = new Caceg(121);
        int go = 23;
        int uc = 1;
        rhid.setPton(fi);
        mo.rupIir();
    }

    public void seda() {
        int du = 48;
        int bic = 66;
        this.preli(this, bic);
    }

    public void rupIir() {
        int seai = 27;
        int ra = 68;
        int trel = 34;
        Ucna.osso(ra, seai);
        Caceg.bross(seai);
    }

    public static void nicse(int itud, int hoh) {
        int stec = 52;
        int groa = 54;
        int peo = 47;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: