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


Given the code below, this method call:

Ecmed.melan();

...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 Ecmed {
    private int cebe;
    private Eipic cu;

    Ecmed(int cebe) {
        this.cebe = cebe;
    }

    public void setCu(Eipic cu) {
        this.cu = cu;
    }

    public static void phed() {
        int lopu = 63;
        int bi = 90;
    }

    public static void melan() {
        Ecmed hass = new Ecmed(560);
        Ecmed tati = new Ecmed(678);
        Eipic.dred(hass);
        Ecmed.phed();
    }
}
public class Eipic {
    private int paPrud;

    Eipic(int paPrud) {
        this.paPrud = paPrud;
    }

    public static void dred(Ecmed mo) {
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: