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


Given the code below, this method call:

Biong.suril();

...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 Biong {
    private int aaIs;
    private Prur cea;
    private Biong fal;
    private Prur siar;

    Biong(int aaIs) {
        this.aaIs = aaIs;
    }

    public void setCea(Prur cea) {
        this.cea = cea;
    }

    public void setFal(Biong fal) {
        this.fal = fal;
    }

    public void setSiar(Prur siar) {
        this.siar = siar;
    }

    public static void suril() {
        int oces = 66;
        Biong i = new Biong(260);
        i.setFal(i);
        Prur.oonar();
        Biong.plia(50, oces, i);
    }

    public static void eaec() {
        int toec = 12;
        int islu = 99;
        int alja = 47;
    }

    public static void spoqes(int ia, int au) {
        int fe = 27;
    }

    public static void cimIth(Prur uoul, Prur hira) {
        int pi = 4;
        int mo = 85;
        uoul.wres(mo, pi);
        HERE;
    }

    public static void plia(int ou, int hi, Biong mec) {
        Prur.jaco();
    }
}
public class Prur {
    private int anCalt;
    private Prur woc;

    Prur(int anCalt) {
        this.anCalt = anCalt;
    }

    public void setWoc(Prur woc) {
        this.woc = woc;
    }

    public void wres(int buer, int pa) {
        int id = 98;
    }

    public static void jaco() {
    }

    public static void oonar() {
        new Prur(117).siler(new Prur(774), new Biong(967));
        Biong.spoqes(11, 10);
    }

    public void siler(Prur fing, Biong as) {
        as.setSiar(this);
        this.dekqoc();
    }

    public void dekqoc() {
        Prur pren = new Prur(316);
        Prur irti = new Prur(43);
        pren.setWoc(irti);
        Biong.cimIth(irti, pren);
        Biong.eaec();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: