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


Given the code below, this method call:

Riiw.hisest();

...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 Riiw {
    private int gorm;
    private Thev oll;

    Riiw(int gorm) {
        this.gorm = gorm;
    }

    public void setOll(Thev oll) {
        this.oll = oll;
    }

    public static void hisest() {
        new Thev(191).qonEba();
        Thev.icper();
    }

    public static void erge() {
        Thev cous = new Thev(570);
        Riiw iast = new Riiw(628);
        Thev.vuts();
        iast.setOll(cous);
        HERE;
    }
}
public class Thev {
    private int lio;
    private Riiw ec;

    Thev(int lio) {
        this.lio = lio;
    }

    public void setEc(Riiw ec) {
        this.ec = ec;
    }

    public void qonEba() {
        int plen = 10;
        Riiw ar = new Riiw(362);
        this.setEc(ar);
        Riiw.erge();
    }

    public static void icper() {
        int isha = 18;
    }

    public static void vuts() {
        int cedd = 58;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: