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


Given the code below, this method call:

Cict.enga();

...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 Cict {
    private int pec;
    private Sint pewu;

    Cict(int pec) {
        this.pec = pec;
    }

    public void setPewu(Sint pewu) {
        this.pewu = pewu;
    }

    public static void enga() {
        Cict u = new Cict(617);
        Sint de = new Sint(998);
        u.helfa(u, new Cict(438));
        u.setPewu(de);
        Sint.saus();
    }

    public void helfa(Cict ux, Cict oin) {
    }
}
public class Sint {
    private int imGo;

    Sint(int imGo) {
        this.imGo = imGo;
    }

    public static void saus() {
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: