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


Given the code below, this method call:

Siawa.larlas();

...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 Siawa {
    private int eple;
    private Siawa os;

    Siawa(int eple) {
        this.eple = eple;
    }

    public void setOs(Siawa os) {
        this.os = os;
    }

    public static void larlas() {
        new Ble(983).eass();
        new Ble(779).puel(new Siawa(131), new Siawa(256));
    }
}
public class Ble {
    private int cer;

    Ble(int cer) {
        this.cer = cer;
    }

    public void puel(Siawa ha, Siawa ol) {
        ol.setOs(ha);
        HERE;
    }

    public void eass() {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: