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


Given the code below, this method call:

Sas.ouen();

...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 Sas {
    private int sabap;
    private Sas iea;
    private Ror shie;
    private Ror sul;
    private Sas sa;

    Sas(int sabap) {
        this.sabap = sabap;
    }

    public void setIea(Sas iea) {
        this.iea = iea;
    }

    public void setShie(Ror shie) {
        this.shie = shie;
    }

    public void setSul(Ror sul) {
        this.sul = sul;
    }

    public void setSa(Sas sa) {
        this.sa = sa;
    }

    public static void ouen() {
        Ror.blen(new Sas(655));
    }

    public static void udaGir(Ror saun) {
        int ba = 44;
        Ror gi = new Ror(865);
        Sas wic = new Sas(295);
        int iar = 60;
        wic.setShie(gi);
        gi.olir();
        Ror.oolni(ba);
    }
}
public class Ror {
    private int pusm;

    Ror(int pusm) {
        this.pusm = pusm;
    }

    public static void blen(Sas hacs) {
        Ror foc = new Ror(70);
        int nulo = 20;
        hacs.setSul(foc);
        Sas.udaGir(foc);
        foc.caceir(hacs, foc);
    }

    public void engje(Ror ris) {
        HERE;
        ris.pouShurex(this, ris, ris);
    }

    public static void muou(Ror cer, Ror epe) {
        Sas al = new Sas(127);
        Sas kes = new Sas(276);
        Ror sto = new Ror(67);
    }

    public void pouShurex(Ror liab, Ror ost, Ror is) {
    }

    public void caceir(Sas sio, Ror ea) {
        int oa = 7;
    }

    public void olir() {
        int vos = 85;
        Sas spir = new Sas(992);
        int ceso = 97;
        Ror.muou(this, new Ror(597));
        spir.setShie(this);
        new Ror(573).engje(this);
    }

    public static void oolni(int aric) {
        int ra = 43;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: