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


Given the code below, this method call:

Geca.ponunt();

...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 Geca {
    private int hiAslas;
    private Geca nees;
    private Isoo ce;

    Geca(int hiAslas) {
        this.hiAslas = hiAslas;
    }

    public void setNees(Geca nees) {
        this.nees = nees;
    }

    public void setCe(Isoo ce) {
        this.ce = ce;
    }

    public void hilpou() {
        int peu = 22;
        int boi = 68;
    }

    public void rint(Isoo prea, Geca moad) {
        this.setNees(moad);
        new Geca(808).onme(this);
        this.hilpou();
    }

    public void onme(Geca dek) {
        this.setNees(dek);
        HERE;
    }

    public static void ponunt() {
        Geca.iasEciop();
        new Geca(260).rint(new Isoo(647), new Geca(349));
    }

    public static void iasEciop() {
        Geca fo = new Geca(202);
    }
}
public class Isoo {
    private int ucCioal;

    Isoo(int ucCioal) {
        this.ucCioal = ucCioal;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: