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


Given the code below, this method call:

Pux.iaesm();

...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 Pux {
    private int onkid;

    Pux(int onkid) {
        this.onkid = onkid;
    }

    public void tadorn() {
        Nin.pren();
        HERE;
    }

    public static void iaesm() {
        Pux pra = new Pux(149);
        Pux moal = new Pux(630);
        new Pux(736).tadorn();
    }
}
public class Nin {
    private int ilill;
    private Pux on;

    Nin(int ilill) {
        this.ilill = ilill;
    }

    public void setOn(Pux on) {
        this.on = on;
    }

    public static void pren() {
        int gead = 59;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: