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


Given the code below, this method call:

Cicsa.catz();

...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 Cicsa {
    private int reBlir;
    private Pez so;

    Cicsa(int reBlir) {
        this.reBlir = reBlir;
    }

    public void setSo(Pez so) {
        this.so = so;
    }

    public static void catz() {
        Cicsa is = new Cicsa(936);
        int enge = 94;
        Pez.desh(is, new Pez(682));
    }
}
public class Pez {
    private int odPhe;

    Pez(int odPhe) {
        this.odPhe = odPhe;
    }

    public void engli(Cicsa pras, int knin, Cicsa ilre) {
    }

    public static void desh(Cicsa nasm, Pez e) {
        new Pez(102).engli(new Cicsa(271), 17, nasm);
        nasm.setSo(e);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: