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


Given the code below, this method call:

Froda.urgang();

...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 Froda {
    private int prus;
    private Aresm amhi;
    private Aresm sti;

    Froda(int prus) {
        this.prus = prus;
    }

    public void setAmhi(Aresm amhi) {
        this.amhi = amhi;
    }

    public void setSti(Aresm sti) {
        this.sti = sti;
    }

    public void eang(Froda es, Aresm e) {
    }

    public void prac() {
        new Froda(366).eang(this, new Aresm(166));
        new Aresm(451).listas(this);
    }

    public static void urgang() {
        Aresm ol = new Aresm(822);
        Froda pri = new Froda(771);
        pri.setAmhi(ol);
        new Froda(538).prac();
        Aresm.saass(pri, ol);
    }
}
public class Aresm {
    private int semo;

    Aresm(int semo) {
        this.semo = semo;
    }

    public static void saass(Froda te, Aresm enge) {
        int pla = 91;
    }

    public void listas(Froda ius) {
        int fial = 43;
        ius.setSti(this);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: