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


Given the code below, this method call:

Gle.ston();

...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 Gle {
    private int ang;
    private Cavuw ar;

    Gle(int ang) {
        this.ang = ang;
    }

    public void setAr(Cavuw ar) {
        this.ar = ar;
    }

    public static void ston() {
        Gle.pespo(new Cavuw(958), new Cavuw(806), new Cavuw(105));
    }

    public static void pespo(Cavuw de, Cavuw cio, Cavuw afe) {
        afe.setKoos(de);
        Cavuw.praess(19, de);
        new Gle(707).olcewn();
    }

    public void olcewn() {
        Gle onch = new Gle(545);
        int thoc = 84;
    }
}
public class Cavuw {
    private int erStel;
    private Cavuw koos;

    Cavuw(int erStel) {
        this.erStel = erStel;
    }

    public void setKoos(Cavuw koos) {
        this.koos = koos;
    }

    public static void pronir(Cavuw ool, int a, Cavuw skec) {
    }

    public static void praess(int hio, Cavuw fe) {
        Cavuw.pronir(new Cavuw(403), hio, fe);
        fe.setKoos(fe);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: