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


Given the code below, this method call:

Iwhet.fimEvost();

...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 Iwhet {
    private int ciac;
    private Iwhet acni;

    Iwhet(int ciac) {
        this.ciac = ciac;
    }

    public void setAcni(Iwhet acni) {
        this.acni = acni;
    }

    public void souru(Iwhet fa, int ad) {
        fa.setAcni(this);
        HERE;
    }

    public static void fimEvost() {
        int fu = 67;
        new Iwhet(658).scrid(fu, new Iwhet(617));
        new Iwhet(273).souru(new Iwhet(823), fu);
    }

    public void scrid(int sost, Iwhet ca) {
    }
}
public class Pleng {
    private int suRe;

    Pleng(int suRe) {
        this.suRe = suRe;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: