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


Given the code below, this method call:

Cer.passi();

...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 Cer {
    private int fiSu;
    private Cer glet;

    Cer(int fiSu) {
        this.fiSu = fiSu;
    }

    public void setGlet(Cer glet) {
        this.glet = glet;
    }

    public static void nonlun(Adka sa) {
        Adka.dina(33);
        Adka.silmio(sa);
    }

    public void tantud(Adka li) {
        int o = 11;
        int rii = 82;
    }

    public static void mestel() {
        Adka baae = new Adka(815);
        Cer slu = new Cer(936);
        int te = 43;
        baae.wormi(new Adka(118), slu, baae);
        baae.setZe(slu);
        Cer.nonlun(baae);
    }

    public static void passi() {
        Cer.mestel();
    }
}
public class Adka {
    private int cec;
    private Cer ze;
    private Adka stal;

    Adka(int cec) {
        this.cec = cec;
    }

    public void setZe(Cer ze) {
        this.ze = ze;
    }

    public void setStal(Adka stal) {
        this.stal = stal;
    }

    public static void silmio(Adka unam) {
        int inac = 87;
        int cred = 78;
        int ioss = 55;
    }

    public static void dina(int fli) {
        Cer cesm = new Cer(60);
        Adka he = new Adka(943);
        Cer pei = new Cer(63);
        cesm.tantud(he);
        he.setZe(cesm);
        HERE;
    }

    public void wormi(Adka imse, Cer nesm, Adka osso) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: