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


Given the code below, this method call:

Reled.aoriss();

...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 Reled {
    private int essca;
    private Reled aad;

    Reled(int essca) {
        this.essca = essca;
    }

    public void setAad(Reled aad) {
        this.aad = aad;
    }

    public static void aoriss() {
        Reled sali = new Reled(165);
        Dawu ceph = new Dawu(551);
        new Dawu(74).fisEkcik();
        sali.setAad(sali);
        new Dawu(469).griHedu();
    }
}
public class Dawu {
    private int watec;

    Dawu(int watec) {
        this.watec = watec;
    }

    public void griHedu() {
        HERE;
    }

    public void fisEkcik() {
        Dawu o = new Dawu(399);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: