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


Given the code below, this method call:

Spo.ockmoc();

...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 Spo {
    private int snec;

    Spo(int snec) {
        this.snec = snec;
    }

    public static void ockmoc() {
        Ecesm is = new Ecesm(11);
        int puc = 51;
        is.draRis(new Spo(827), is, puc);
    }

    public void pethra(Ecesm spes) {
    }
}
public class Ecesm {
    private int emCes;
    private Spo be;

    Ecesm(int emCes) {
        this.emCes = emCes;
    }

    public void setBe(Spo be) {
        this.be = be;
    }

    public void draRis(Spo vo, Ecesm poje, int ohom) {
        new Spo(13).pethra(poje);
        this.setBe(vo);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: