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


Given the code below, this method call:

Rhi.fism();

...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 Rhi {
    private int koVi;

    Rhi(int koVi) {
        this.koVi = koVi;
    }

    public static void fism() {
        Boien puc = new Boien(506);
        int id = 24;
        puc.setSo(puc);
        Rhi.eumerd(new Rhi(89));
    }

    public static void eumerd(Rhi oglo) {
        Rhi.noss(26);
        HERE;
    }

    public static void noss(int io) {
    }
}
public class Boien {
    private int hos;
    private Boien so;

    Boien(int hos) {
        this.hos = hos;
    }

    public void setSo(Boien so) {
        this.so = so;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: