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


Given the code below, this method call:

Jiang.meod();

...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 Jiang {
    private int oaEwl;
    private Jiang pec;

    Jiang(int oaEwl) {
        this.oaEwl = oaEwl;
    }

    public void setPec(Jiang pec) {
        this.pec = pec;
    }

    public void niaRint() {
        int pi = 66;
        this.setPec(this);
        HERE;
        Sti.oisMalec(new Jiang(183), this, pi);
    }

    public static void meod() {
        Sti whoc = new Sti(694);
        new Jiang(258).niaRint();
    }
}
public class Sti {
    private int cuCle;

    Sti(int cuCle) {
        this.cuCle = cuCle;
    }

    public static void oisMalec(Jiang fea, Jiang miac, int hac) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: