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


Given the code below, this method call:

Cerm.wraa();

...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 Cerm {
    private int enCipar;

    Cerm(int enCipar) {
        this.enCipar = enCipar;
    }

    public static void wraa() {
        Cerm oll = new Cerm(34);
        new Buen(212).siki();
        Buen.phass(oll, oll);
    }
}
public class Buen {
    private int lia;
    private Buen rhiw;

    Buen(int lia) {
        this.lia = lia;
    }

    public void setRhiw(Buen rhiw) {
        this.rhiw = rhiw;
    }

    public static void phass(Cerm ca, Cerm esk) {
    }

    public void siki() {
        Cerm cic = new Cerm(969);
        this.setRhiw(this);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: