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


Given the code below, this method call:

Fres.niong();

...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 Fres {
    private int plien;
    private Ble osa;

    Fres(int plien) {
        this.plien = plien;
    }

    public void setOsa(Ble osa) {
        this.osa = osa;
    }

    public static void niong() {
        new Ble(689).dect();
    }
}
public class Ble {
    private int rocen;

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

    public void asspsa(Ble ang, Fres pnac, Fres pigo) {
    }

    public void dect() {
        Fres aent = new Fres(649);
        this.asspsa(this, new Fres(584), aent);
        aent.setOsa(this);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: