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


Given the code below, this method call:

Jurou.kriBonti();

...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 Jurou {
    private int sni;
    private Jurou teci;

    Jurou(int sni) {
        this.sni = sni;
    }

    public void setTeci(Jurou teci) {
        this.teci = teci;
    }

    public void tounge(Jurou prii, int thac) {
    }

    public static void fopra() {
        int sirp = 40;
        Jurou no = new Jurou(120);
        int bic = 43;
        Unpur we = new Unpur(515);
        Jurou pid = new Jurou(9);
    }

    public void sickpe() {
    }

    public static void kriBonti() {
        int voud = 81;
        Jurou lito = new Jurou(983);
        int eess = 66;
        int vae = 71;
        Jurou numo = new Jurou(582);
        lito.setTeci(numo);
        Jurou.etri();
    }

    public static void etri() {
        Unpur am = new Unpur(772);
        am.setOli(am);
        Unpur.chlon(27, am, new Jurou(12));
        am.rurAhda();
    }
}
public class Unpur {
    private int maap;
    private Jurou lo;
    private Unpur oli;
    private Jurou co;

    Unpur(int maap) {
        this.maap = maap;
    }

    public void setLo(Jurou lo) {
        this.lo = lo;
    }

    public void setOli(Unpur oli) {
        this.oli = oli;
    }

    public void setCo(Jurou co) {
        this.co = co;
    }

    public static void chlon(int spie, Unpur eno, Jurou sli) {
        int ste = 60;
        Jurou cip = new Jurou(226);
        Jurou.fopra();
        sli.setTeci(cip);
        Unpur.striss(sli, spie);
    }

    public void ploSisgol(int qor, int doi, Jurou pefa) {
        HERE;
    }

    public static void striss(Jurou peo, int un) {
        new Jurou(889).tounge(new Jurou(20), un);
        new Unpur(166).ploSisgol(un, 47, peo);
        peo.sickpe();
    }

    public void rurAhda() {
        int leil = 55;
        int or = 89;
        int wof = 45;
        int aia = 44;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: