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


Given the code below, this method call:

Ocgua.gicAstswa();

...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 Ocgua {
    private int ful;
    private Ocgua pe;

    Ocgua(int ful) {
        this.ful = ful;
    }

    public void setPe(Ocgua pe) {
        this.pe = pe;
    }

    public void jengi() {
        Ciad spen = new Ciad(271);
    }

    public static void gicAstswa() {
        int ed = 3;
        Ciad.egaGlicka(new Ciad(268), ed);
        Ocgua.eouko(new Ocgua(866), ed);
    }

    public static void eouko(Ocgua la, int da) {
        Ocgua saer = new Ocgua(842);
        saer.setPe(la);
        Ciad.piaed(la, new Ciad(186), saer);
    }
}
public class Ciad {
    private int piSqen;
    private Ocgua bugh;

    Ciad(int piSqen) {
        this.piSqen = piSqen;
    }

    public void setBugh(Ocgua bugh) {
        this.bugh = bugh;
    }

    public static void egaGlicka(Ciad su, int qixo) {
        Ocgua reng = new Ocgua(881);
    }

    public static void piaed(Ocgua ro, Ciad an, Ocgua mul) {
        new Ocgua(122).jengi();
        an.setBugh(mul);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: