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


Given the code below, this method call:

Mied.dospli();

...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 Mied {
    private int odCa;
    private Frios hi;

    Mied(int odCa) {
        this.odCa = odCa;
    }

    public void setHi(Frios hi) {
        this.hi = hi;
    }

    public static void dospli() {
        Frios cesi = new Frios(78);
        Frios.flePropon(cesi, new Frios(235));
    }
}
public class Frios {
    private int okru;

    Frios(int okru) {
        this.okru = okru;
    }

    public void prult(Mied u) {
    }

    public static void flePropon(Frios rol, Frios ste) {
        rol.prult(new Mied(101));
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: