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


Given the code below, this method call:

Freo.vedPeasm();

...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 Freo {
    private int adli;
    private Freo ocir;

    Freo(int adli) {
        this.adli = adli;
    }

    public void setOcir(Freo ocir) {
        this.ocir = ocir;
    }

    public void waper(Wex ther) {
        ther.sontin(this, ther, new Wex(771));
        this.setOcir(this);
        HERE;
    }

    public static void vedPeasm() {
        int daar = 53;
        new Freo(318).waper(new Wex(90));
    }
}
public class Wex {
    private int urk;

    Wex(int urk) {
        this.urk = urk;
    }

    public void sontin(Freo prae, Wex ac, Wex stro) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: