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


Given the code below, this method call:

Ciss.swolsa();

...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 Ciss {
    private int laFiox;
    private Sondi pana;
    private Ciss ca;

    Ciss(int laFiox) {
        this.laFiox = laFiox;
    }

    public void setPana(Sondi pana) {
        this.pana = pana;
    }

    public void setCa(Ciss ca) {
        this.ca = ca;
    }

    public static void swolsa() {
        Ciss gepe = new Ciss(342);
        Sondi fic = new Sondi(820);
        fic.lawco(new Sondi(461));
        fic.setOl(fic);
        new Sondi(684).silp(gepe, new Sondi(970));
    }

    public static void flobir(int rul, int a) {
        int hi = 14;
        int sti = 15;
        Ciss.lonCaint(rul);
        HERE;
    }

    public static void hidbad(int ma, int clu, Sondi nel) {
        int onta = 50;
    }

    public static void lonCaint(int pid) {
        int es = 65;
        int sais = 5;
    }
}
public class Sondi {
    private int becid;
    private Sondi ol;

    Sondi(int becid) {
        this.becid = becid;
    }

    public void setOl(Sondi ol) {
        this.ol = ol;
    }

    public void lawco(Sondi pe) {
    }

    public void silp(Ciss na, Sondi e) {
        Sondi ples = new Sondi(65);
        na.setPana(ples);
        ples.pepra(e);
    }

    public void pepra(Sondi aa) {
        int pio = 77;
        int miar = 27;
        Ciss.hidbad(miar, pio, aa);
        Ciss.flobir(miar, pio);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: