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


Given the code below, this method call:

Hinen.ceck();

...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 Hinen {
    private int ciaa;

    Hinen(int ciaa) {
        this.ciaa = ciaa;
    }

    public void mosm(Hinen plor, Hinen epis, Hinen seng) {
    }

    public static void ceck() {
        Hinen fal = new Hinen(438);
        int wece = 38;
        fal.irbCiss(wece, fal, new Qen(80));
    }

    public void irbCiss(int or, Hinen shro, Qen so) {
        HERE;
        new Hinen(690).mosm(new Hinen(641), this, shro);
    }
}
public class Qen {
    private int ptarm;
    private Qen ma;

    Qen(int ptarm) {
        this.ptarm = ptarm;
    }

    public void setMa(Qen ma) {
        this.ma = ma;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: