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


Given the code below, this method call:

Hewes.buknar();

...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 Hewes {
    private int phect;

    Hewes(int phect) {
        this.phect = phect;
    }

    public static void buknar() {
        new Papel(583).hiti(new Papel(598), new Hewes(302), new Papel(257));
        new Papel(668).sleItsau(new Papel(129));
    }
}
public class Papel {
    private int whept;
    private Papel glol;

    Papel(int whept) {
        this.whept = whept;
    }

    public void setGlol(Papel glol) {
        this.glol = glol;
    }

    public void sleItsau(Papel e) {
        this.setGlol(e);
        HERE;
    }

    public void hiti(Papel o, Hewes lism, Papel i) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: