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


Given the code below, this method call:

Ebin.scoRopaw();

...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 Ebin {
    private int ecPa;

    Ebin(int ecPa) {
        this.ecPa = ecPa;
    }

    public static void scoRopaw() {
        new Niar(745).resm(new Ebin(225), new Ebin(448));
    }
}
public class Niar {
    private int ciCles;
    private Niar es;

    Niar(int ciCles) {
        this.ciCles = ciCles;
    }

    public void setEs(Niar es) {
        this.es = es;
    }

    public void hiuas(Ebin glo, Ebin ne, Niar iap) {
    }

    public void resm(Ebin isi, Ebin a) {
        HERE;
        this.hiuas(a, isi, this);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: