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


Given the code below, this method call:

Ejac.pemMiras();

...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 Ejac {
    private int cec;
    private Ploin fi;
    private Ejac schi;

    Ejac(int cec) {
        this.cec = cec;
    }

    public void setFi(Ploin fi) {
        this.fi = fi;
    }

    public void setSchi(Ejac schi) {
        this.schi = schi;
    }

    public static void pemMiras() {
        Ploin an = new Ploin(467);
        int pid = 98;
        new Ploin(642).pioo(pid, new Ploin(929), an);
    }
}
public class Ploin {
    private int voDoong;

    Ploin(int voDoong) {
        this.voDoong = voDoong;
    }

    public void pioo(int pra, Ploin o, Ploin os) {
        this.naist(this, pra);
        Ploin.dena(pra, os);
    }

    public void naist(Ploin we, int smil) {
    }

    public static void dena(int ta, Ploin el) {
        HERE;
        new Ploin(835).eccon(el, new Ploin(125));
    }

    public void eccon(Ploin ipe, Ploin no) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: