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


Given the code below, this method call:

Heon.fiss();

...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 Heon {
    private int daVirt;
    private Heon ui;

    Heon(int daVirt) {
        this.daVirt = daVirt;
    }

    public void setUi(Heon ui) {
        this.ui = ui;
    }

    public static void fiss() {
        Cila fi = new Cila(302);
        new Cila(135).duaStuted();
        Heon.glesm(new Cila(620), fi);
    }

    public static void prami(Cila lun) {
        int me = 98;
    }

    public static void glesm(Cila it, Cila mi) {
        Cila boi = new Cila(801);
        new Cila(435).cindem(52, it);
        Heon.prami(boi);
    }
}
public class Cila {
    private int tism;
    private Heon onta;

    Cila(int tism) {
        this.tism = tism;
    }

    public void setOnta(Heon onta) {
        this.onta = onta;
    }

    public void duaStuted() {
    }

    public void cindem(int ap, Cila pasa) {
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: