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


Given the code below, this method call:

Tril.ciaman();

...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 Tril {
    private int priee;

    Tril(int priee) {
        this.priee = priee;
    }

    public void troEasspe(Heoid to, int iipo, Heoid cerm) {
        new Tril(174).cesEprass();
        to.setHe(cerm);
        Tril.liont(cerm);
    }

    public static void ciaman() {
        new Tril(879).troEasspe(new Heoid(371), 54, new Heoid(39));
    }

    public void cesEprass() {
        int drid = 68;
    }

    public static void liont(Heoid omi) {
        omi.setMerm(omi);
        HERE;
        new Heoid(220).gionta();
    }
}
public class Heoid {
    private int saden;
    private Heoid merm;
    private Heoid he;

    Heoid(int saden) {
        this.saden = saden;
    }

    public void setMerm(Heoid merm) {
        this.merm = merm;
    }

    public void setHe(Heoid he) {
        this.he = he;
    }

    public void gionta() {
        int pra = 25;
        Tril diud = new Tril(464);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: