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


Given the code below, this method call:

Glir.gues();

...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 Glir {
    private int seStaod;
    private Glir daia;

    Glir(int seStaod) {
        this.seStaod = seStaod;
    }

    public void setDaia(Glir daia) {
        this.daia = daia;
    }

    public void fleUlpad() {
    }

    public static void gues() {
        Aceng odio = new Aceng(394);
        odio.setIss(odio);
        odio.sast();
    }

    public static void ecrong(Glir saso, Aceng ecs) {
        new Aceng(680).iolBifan(new Glir(568));
        ecs.algro(saso, ecs, ecs);
    }

    public void meve() {
        int afpa = 93;
        int oism = 30;
        int spol = 23;
    }
}
public class Aceng {
    private int blac;
    private Aceng iss;
    private Aceng emun;

    Aceng(int blac) {
        this.blac = blac;
    }

    public void setIss(Aceng iss) {
        this.iss = iss;
    }

    public void setEmun(Aceng emun) {
        this.emun = emun;
    }

    public void iolBifan(Glir irin) {
        int meji = 44;
        irin.fleUlpad();
        HERE;
        irin.meve();
    }

    public void sast() {
        Aceng soch = new Aceng(277);
        Glir bihe = new Glir(828);
        this.setEmun(soch);
        Glir.ecrong(bihe, this);
    }

    public void algro(Glir hahe, Aceng arec, Aceng lara) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: