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


Given the code below, this method call:

Folci.sper();

...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 Folci {
    private int ema;
    private Folci ba;
    private Rapra ioup;

    Folci(int ema) {
        this.ema = ema;
    }

    public void setBa(Folci ba) {
        this.ba = ba;
    }

    public void setIoup(Rapra ioup) {
        this.ioup = ioup;
    }

    public static void sper() {
        Rapra.stec();
    }
}
public class Rapra {
    private int otbri;
    private Rapra mu;

    Rapra(int otbri) {
        this.otbri = otbri;
    }

    public void setMu(Rapra mu) {
        this.mu = mu;
    }

    public static void praAsism() {
        int sarm = 31;
        int tul = 16;
        Rapra ieth = new Rapra(119);
    }

    public void iprom() {
        this.setMu(this);
        HERE;
    }

    public static void stec() {
        Rapra.dioJidce(new Rapra(449), new Rapra(732), new Rapra(474));
        Rapra.tispe();
    }

    public void zateh(Folci ce, Rapra etre, Rapra al) {
    }

    public static void tispe() {
    }

    public static void dioJidce(Rapra mooo, Rapra pio, Rapra da) {
        Folci chre = new Folci(863);
        Rapra.praAsism();
        pio.setMu(mooo);
        new Rapra(889).iprom();
        da.zateh(chre, da, pio);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: