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


Given the code below, this method call:

Mashe.wous();

...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 Mashe {
    private int vanur;
    private Elil cuph;

    Mashe(int vanur) {
        this.vanur = vanur;
    }

    public void setCuph(Elil cuph) {
        this.cuph = cuph;
    }

    public void schini() {
        int dala = 6;
        int rae = 11;
        Elil.prou(rae, dala, new Mashe(559));
    }

    public static void wous() {
        Elil da = new Elil(415);
        int pi = 22;
        Mashe wiol = new Mashe(193);
        wiol.setCuph(da);
        wiol.schini();
    }

    public void diso(Mashe e, int swi, int ici) {
    }
}
public class Elil {
    private int eaplu;
    private Elil cin;

    Elil(int eaplu) {
        this.eaplu = eaplu;
    }

    public void setCin(Elil cin) {
        this.cin = cin;
    }

    public static void prou(int su, int ewod, Mashe ris) {
        new Elil(485).curde(ris, ewod, new Elil(363));
        HERE;
        ris.diso(ris, su, ewod);
    }

    public void curde(Mashe i, int geoc, Elil hion) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: