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


Given the code below, this method call:

Ucfla.ubal();

...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 Ucfla {
    private int fla;
    private Ucfla us;
    private Ucfla ac;

    Ucfla(int fla) {
        this.fla = fla;
    }

    public void setUs(Ucfla us) {
        this.us = us;
    }

    public void setAc(Ucfla ac) {
        this.ac = ac;
    }

    public static void ubal() {
        Ucfla dic = new Ucfla(730);
        Ert cisa = new Ert(335);
        Ucfla na = new Ucfla(184);
        na.podud(new Ert(741), dic);
        na.setUs(dic);
        Ert.prucda(new Ert(955));
    }

    public void podud(Ert su, Ucfla mul) {
        int acho = 83;
    }

    public static void oaptiu(Ucfla ee) {
        int joc = 21;
        int issi = 68;
    }

    public void noihac(int sast, int ipu) {
        int aspe = 90;
        Ucfla.oaptiu(this);
        HERE;
    }

    public void hedpo(int et) {
        int ni = 9;
        int nass = 96;
        this.noihac(2, ni);
    }

    public void asserd(Ucfla nir) {
        int phoa = 27;
        int he = 92;
    }
}
public class Ert {
    private int woUe;
    private Ert pisi;

    Ert(int woUe) {
        this.woUe = woUe;
    }

    public void setPisi(Ert pisi) {
        this.pisi = pisi;
    }

    public static void prucda(Ert ogh) {
        int mebe = 89;
        Ucfla patz = new Ucfla(263);
        int ol = 95;
        patz.setAc(patz);
        patz.hedpo(mebe);
        patz.asserd(patz);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: