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


Given the code below, this method call:

Foi.doph();

...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 Foi {
    private int esmo;
    private Caur pha;

    Foi(int esmo) {
        this.esmo = esmo;
    }

    public void setPha(Caur pha) {
        this.pha = pha;
    }

    public static void doph() {
        Foi.udel();
        Caur.giasu(new Foi(202), new Caur(372), new Foi(284));
    }

    public static void udel() {
        Foi uwba = new Foi(935);
    }
}
public class Caur {
    private int hiIha;

    Caur(int hiIha) {
        this.hiIha = hiIha;
    }

    public static void giasu(Foi a, Caur liao, Foi dou) {
        dou.setPha(liao);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: