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


Given the code below, this method call:

Mecde.utpewl();

...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 Mecde {
    private int iko;
    private Mecde ood;

    Mecde(int iko) {
        this.iko = iko;
    }

    public void setOod(Mecde ood) {
        this.ood = ood;
    }

    public static void utpewl() {
        Mecde sual = new Mecde(183);
        Alosm pasm = new Alosm(473);
        sual.setOod(sual);
        new Mecde(581).meriou();
        pasm.aespas(pasm, sual);
    }

    public void meriou() {
        int en = 60;
        HERE;
    }
}
public class Alosm {
    private int zurma;

    Alosm(int zurma) {
        this.zurma = zurma;
    }

    public void aespas(Alosm stes, Mecde ge) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: