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


Given the code below, this method call:

Osark.ganess();

...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 Osark {
    private int anbod;

    Osark(int anbod) {
        this.anbod = anbod;
    }

    public static void ganess() {
        new Twaro(419).atco();
        Osark.veuge(new Twaro(779), new Osark(868), new Twaro(990));
    }

    public static void veuge(Twaro sqaa, Osark ui, Twaro damo) {
        damo.setPeu(ui);
        HERE;
    }
}
public class Twaro {
    private int goic;
    private Osark peu;

    Twaro(int goic) {
        this.goic = goic;
    }

    public void setPeu(Osark peu) {
        this.peu = peu;
    }

    public void atco() {
        int ciod = 84;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: