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


Given the code below, this method call:

Uinse.bliden();

...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 Uinse {
    private int craad;
    private Ramol it;

    Uinse(int craad) {
        this.craad = craad;
    }

    public void setIt(Ramol it) {
        this.it = it;
    }

    public static void bliden() {
        new Ramol(843).vaeWhocsa(new Uinse(929), new Ramol(977), new Ramol(124));
    }
}
public class Ramol {
    private int caPle;

    Ramol(int caPle) {
        this.caPle = caPle;
    }

    public void vaeWhocsa(Uinse re, Ramol sa, Ramol rair) {
        re.setIt(sa);
        HERE;
        sa.sexoc(this);
    }

    public void sexoc(Ramol ne) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: