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


Given the code below, this method call:

Relir.prid();

...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 Relir {
    private int cou;

    Relir(int cou) {
        this.cou = cou;
    }

    public static void prid() {
        Omass ufea = new Omass(589);
        ufea.resm();
        ufea.irmass();
    }
}
public class Omass {
    private int wiFrio;
    private Relir pu;

    Omass(int wiFrio) {
        this.wiFrio = wiFrio;
    }

    public void setPu(Relir pu) {
        this.pu = pu;
    }

    public void resm() {
        Relir psed = new Relir(933);
        this.setPu(psed);
        HERE;
    }

    public void irmass() {
        Omass ra = new Omass(657);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: