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


Given the code below, this method call:

Prexo.meid();

...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 Prexo {
    private int otho;
    private Cieua ee;
    private Prexo eo;

    Prexo(int otho) {
        this.otho = otho;
    }

    public void setEe(Cieua ee) {
        this.ee = ee;
    }

    public void setEo(Prexo eo) {
        this.eo = eo;
    }

    public void iocCea(int o, Prexo pi, int oine) {
    }

    public void gicia(int er) {
    }

    public static void meid() {
        int kna = 47;
        Cieua hiff = new Cieua(193);
        new Prexo(354).gicia(kna);
        hiff.setTro(hiff);
        Cieua.mioZoudo(kna);
    }

    public void debois(int ciar) {
        HERE;
        Cieua.eant(ciar);
    }
}
public class Cieua {
    private int cuc;
    private Cieua tro;

    Cieua(int cuc) {
        this.cuc = cuc;
    }

    public void setTro(Cieua tro) {
        this.tro = tro;
    }

    public static void eant(int nio) {
    }

    public void koct(Prexo toc, Prexo ar) {
        toc.debois(57);
    }

    public static void mioZoudo(int mua) {
        Prexo e = new Prexo(720);
        Cieua ci = new Cieua(27);
        e.iocCea(mua, new Prexo(300), 41);
        e.setEe(ci);
        new Cieua(77).koct(new Prexo(460), e);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: