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


Given the code below, this method call:

Uac.iless();

...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 Uac {
    private int sqol;
    private Uac gri;
    private Uac blen;

    Uac(int sqol) {
        this.sqol = sqol;
    }

    public void setGri(Uac gri) {
        this.gri = gri;
    }

    public void setBlen(Uac blen) {
        this.blen = blen;
    }

    public static void iless() {
        Uac chre = new Uac(411);
        chre.setBlen(chre);
        new Uac(989).osme();
        Oal.fanel(chre, chre);
    }

    public void erdi(int puel) {
        Uac sost = new Uac(467);
        int cel = 60;
        HERE;
    }

    public void osme() {
        Oal.festac(new Uac(874), this, new Oal(368));
        this.setGri(this);
        Oal.mebe(new Oal(722));
    }
}
public class Oal {
    private int racre;
    private Oal ru;

    Oal(int racre) {
        this.racre = racre;
    }

    public void setRu(Oal ru) {
        this.ru = ru;
    }

    public static void neouc(int kur, int ble) {
    }

    public static void festac(Uac prer, Uac ston, Oal adre) {
    }

    public static void fanel(Uac dida, Uac ci) {
        int si = 12;
        int os = 21;
    }

    public static void mebe(Oal bler) {
        int el = 87;
        Oal.neouc(92, el);
        new Uac(363).erdi(el);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: