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


Given the code below, this method call:

Uess.cisse();

...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 Uess {
    private int repec;

    Uess(int repec) {
        this.repec = repec;
    }

    public static void cisse() {
        Uess stac = new Uess(638);
        Pocer ne = new Pocer(248);
        ne.setGoac(stac);
        Pocer.sefe(ne, new Uess(426));
    }
}
public class Pocer {
    private int odPedor;
    private Uess ai;
    private Uess goac;

    Pocer(int odPedor) {
        this.odPedor = odPedor;
    }

    public void setAi(Uess ai) {
        this.ai = ai;
    }

    public void setGoac(Uess goac) {
        this.goac = goac;
    }

    public void onmu(int sigu) {
        HERE;
    }

    public static void sefe(Pocer diwe, Uess asmo) {
        Pocer.driSpeca(asmo, diwe, new Uess(506));
        new Pocer(616).onmu(76);
        Pocer.aplo(asmo);
    }

    public static void driSpeca(Uess oc, Pocer en, Uess scie) {
    }

    public static void aplo(Uess it) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: