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


Given the code below, this method call:

Eoi.trol();

...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 Eoi {
    private int dopre;
    private Madop ca;

    Eoi(int dopre) {
        this.dopre = dopre;
    }

    public void setCa(Madop ca) {
        this.ca = ca;
    }

    public static void trol() {
        Eoi lu = new Eoi(747);
        Madop seh = new Madop(623);
        int wo = 59;
        Madop.proni();
        lu.setCa(seh);
        Madop.dicDacsa();
    }
}
public class Madop {
    private int orCeu;
    private Eoi am;

    Madop(int orCeu) {
        this.orCeu = orCeu;
    }

    public void setAm(Eoi am) {
        this.am = am;
    }

    public static void mathi(Madop miol, Madop nung, Madop im) {
    }

    public static void proni() {
        Eoi ac = new Eoi(513);
        Madop mo = new Madop(882);
        Madop er = new Madop(92);
    }

    public static void dicDacsa() {
        Madop grec = new Madop(900);
        Madop.orea(grec);
    }

    public static void orea(Madop ost) {
        HERE;
        Madop.mathi(ost, new Madop(419), new Madop(863));
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: