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


Given the code below, this method call:

Mial.mirn();

...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 Mial {
    private int nanro;
    private Mial mera;

    Mial(int nanro) {
        this.nanro = nanro;
    }

    public void setMera(Mial mera) {
        this.mera = mera;
    }

    public static void mirn() {
        Mial ed = new Mial(650);
        Diu.ufid(ed);
        ed.setMera(ed);
        new Diu(706).ookPurk(ed);
    }
}
public class Diu {
    private int liast;

    Diu(int liast) {
        this.liast = liast;
    }

    public static void ufid(Mial di) {
        Mial sirp = new Mial(633);
    }

    public void ookPurk(Mial a) {
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: