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


Given the code below, this method call:

Eoss.feinth();

...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 Eoss {
    private int orpro;
    private Esroc aco;
    private Esroc bitu;

    Eoss(int orpro) {
        this.orpro = orpro;
    }

    public void setAco(Esroc aco) {
        this.aco = aco;
    }

    public void setBitu(Esroc bitu) {
        this.bitu = bitu;
    }

    public static void feinth() {
        Esroc oea = new Esroc(882);
        Eoss gri = new Eoss(2);
        new Esroc(893).ocbu();
        new Esroc(367).beold(gri, oea);
    }

    public static void onko(Eoss ol) {
        int bli = 1;
        int ci = 75;
        HERE;
    }
}
public class Esroc {
    private int elser;

    Esroc(int elser) {
        this.elser = elser;
    }

    public void beold(Eoss hess, Esroc pri) {
        pri.wipsul(hess, new Esroc(271));
        hess.setBitu(pri);
        Eoss.onko(hess);
    }

    public void wipsul(Eoss ur, Esroc clen) {
    }

    public void ocbu() {
        int psin = 55;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: