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


Given the code below, this method call:

Parne.criac();

...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 Parne {
    private int ior;
    private Mie cio;

    Parne(int ior) {
        this.ior = ior;
    }

    public void setCio(Mie cio) {
        this.cio = cio;
    }

    public static void criac() {
        int mori = 94;
        Parne.certad(97, mori, new Parne(317));
        new Parne(407).biul(mori, new Mie(375), new Parne(910));
    }

    public void biul(int ci, Mie tast, Parne coc) {
        this.setCio(tast);
        HERE;
    }

    public static void certad(int er, int chus, Parne el) {
    }
}
public class Mie {
    private int isxis;

    Mie(int isxis) {
        this.isxis = isxis;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: