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


Given the code below, this method call:

Atha.chix();

...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 Atha {
    private int tiFepla;
    private Atha biss;

    Atha(int tiFepla) {
        this.tiFepla = tiFepla;
    }

    public void setBiss(Atha biss) {
        this.biss = biss;
    }

    public void psuBamved(Nir troc, int he) {
    }

    public static void chix() {
        int odon = 60;
        Atha mase = new Atha(235);
        mase.setBiss(mase);
        new Nir(626).rotoan(new Nir(135));
    }
}
public class Nir {
    private int piCui;
    private Nir ao;

    Nir(int piCui) {
        this.piCui = piCui;
    }

    public void setAo(Nir ao) {
        this.ao = ao;
    }

    public void rotoan(Nir imen) {
        Nir.enci(imen, this);
        imen.setAo(this);
        Nir.ioccen(92);
    }

    public static void ioccen(int brau) {
        HERE;
        new Atha(765).psuBamved(new Nir(956), brau);
    }

    public static void enci(Nir sca, Nir bir) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: