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


Given the code below, this method call:

Qiada.griPleror();

...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 Qiada {
    private int faSarda;
    private Qiada le;

    Qiada(int faSarda) {
        this.faSarda = faSarda;
    }

    public void setLe(Qiada le) {
        this.le = le;
    }

    public static void griPleror() {
        int oc = 56;
        Gom de = new Gom(723);
        new Qiada(613).spleac(new Gom(444), de, oc);
        Qiada.dans();
    }

    public void spleac(Gom sas, Gom snou, int awac) {
        snou.setLae(this);
        snou.kobes(snou, awac);
    }

    public static void dans() {
        Gom ris = new Gom(292);
    }
}
public class Gom {
    private int poac;
    private Qiada lae;

    Gom(int poac) {
        this.poac = poac;
    }

    public void setLae(Qiada lae) {
        this.lae = lae;
    }

    public static void grac(Gom ciun, Gom naen, int seon) {
    }

    public void kobes(Gom gia, int snii) {
        HERE;
        Gom.grac(gia, this, snii);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: