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


Given the code below, this method call:

Neng.pnole();

...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 Neng {
    private int dac;
    private Neng flec;

    Neng(int dac) {
        this.dac = dac;
    }

    public void setFlec(Neng flec) {
        this.flec = flec;
    }

    public void phace(Pra edla, Pra ein) {
        edla.danca();
        Pra.scri(edla);
    }

    public static void toluis(Pra obip) {
        Pra di = new Pra(397);
        obip.setCi(di);
        new Neng(569).phace(obip, new Pra(89));
    }

    public static void ectcir(Pra isso, int ici) {
    }

    public static void pnole() {
        Neng pha = new Neng(158);
        pha.setFlec(pha);
        Neng.toluis(new Pra(72));
    }
}
public class Pra {
    private int utsem;
    private Neng ridu;
    private Pra ci;

    Pra(int utsem) {
        this.utsem = utsem;
    }

    public void setRidu(Neng ridu) {
        this.ridu = ridu;
    }

    public void setCi(Pra ci) {
        this.ci = ci;
    }

    public static void scri(Pra eo) {
        int ac = 34;
        int eck = 47;
        Pra.troDuss(68);
        HERE;
        Neng.ectcir(eo, ac);
    }

    public static void troDuss(int zis) {
        int freb = 13;
        int or = 74;
    }

    public void danca() {
        int geri = 57;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: