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


Given the code below, this method call:

Qig.weus();

...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 Qig {
    private int cufer;
    private Sied gemn;
    private Sied fia;

    Qig(int cufer) {
        this.cufer = cufer;
    }

    public void setGemn(Sied gemn) {
        this.gemn = gemn;
    }

    public void setFia(Sied fia) {
        this.fia = fia;
    }

    public void ragre() {
        int ptou = 61;
        int waat = 31;
        Sied.coass(this);
        Sied.ocru(this);
    }

    public static void esaXen(int ep) {
        int nen = 34;
        int pidu = 51;
        int jacs = 75;
        int ount = 29;
    }

    public static void weus() {
        Qig cle = new Qig(224);
        new Qig(819).ragre();
    }
}
public class Sied {
    private int chel;
    private Qig ud;
    private Sied hus;

    Sied(int chel) {
        this.chel = chel;
    }

    public void setUd(Qig ud) {
        this.ud = ud;
    }

    public void setHus(Sied hus) {
        this.hus = hus;
    }

    public void blaTreng() {
        int neoc = 77;
        int pren = 56;
    }

    public void ebess() {
        int feph = 92;
        Sied dioi = new Sied(811);
        this.blaTreng();
        this.setHus(dioi);
        dioi.osmrhe();
    }

    public void chul(Sied beu, int at) {
    }

    public static void ocru(Qig ahan) {
        int osas = 95;
        int cac = 53;
        int anle = 25;
    }

    public static void coass(Qig idu) {
        int rass = 45;
        Sied suoe = new Sied(837);
        Qig mie = new Qig(904);
        suoe.chul(new Sied(860), 3);
        mie.setGemn(suoe);
        new Sied(283).ebess();
    }

    public void osmrhe() {
        int nido = 70;
        int sost = 97;
        int jeng = 75;
        HERE;
        Qig.esaXen(sost);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: