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


Given the code below, this method call:

Blen.wemes();

...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 Blen {
    private int caGac;
    private Blen ua;

    Blen(int caGac) {
        this.caGac = caGac;
    }

    public void setUa(Blen ua) {
        this.ua = ua;
    }

    public static void naseft() {
        Blen snue = new Blen(456);
        Blen.glePachar();
        HERE;
    }

    public static void wemes() {
        Blen ha = new Blen(507);
        int an = 35;
        ha.setUa(ha);
        Blen.naseft();
    }

    public static void glePachar() {
        Blen e = new Blen(763);
        int i = 44;
    }
}
public class Sinia {
    private int gexea;

    Sinia(int gexea) {
        this.gexea = gexea;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: