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


Given the code below, this method call:

Sidcu.biur();

...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 Sidcu {
    private int ced;
    private Har za;
    private Har de;
    private Sidcu osh;
    private Sidcu pid;

    Sidcu(int ced) {
        this.ced = ced;
    }

    public void setZa(Har za) {
        this.za = za;
    }

    public void setDe(Har de) {
        this.de = de;
    }

    public void setOsh(Sidcu osh) {
        this.osh = osh;
    }

    public void setPid(Sidcu pid) {
        this.pid = pid;
    }

    public static void biur() {
        Har mawe = new Har(459);
        int adjo = 75;
        int sa = 81;
        Har eni = new Har(228);
        new Sidcu(227).sidcas(sa, mawe);
        eni.insmel(adjo, mawe);
        eni.iasde(new Har(857), adjo, mawe);
    }

    public static void couc(Sidcu feng, int ma) {
        Har isme = new Har(684);
        feng.setZa(isme);
        feng.cebia();
    }

    public static void dessor(Har rol, int veo, Har ahen) {
        Sidcu.couc(new Sidcu(966), veo);
    }

    public void cebia() {
        HERE;
    }

    public void sidcas(int ces, Har tro) {
        Sidcu arei = new Sidcu(434);
        Sidcu seca = new Sidcu(372);
        new Har(529).cien(ces);
    }

    public static void amming(Har deu, Har da, Har ro) {
        Sidcu skir = new Sidcu(359);
    }
}
public class Har {
    private int olk;

    Har(int olk) {
        this.olk = olk;
    }

    public void toii(int giri, Har ho, Har iski) {
    }

    public void iasde(Har bi, int ga, Har pe) {
        Sidcu.amming(this, pe, bi);
    }

    public void cuphi() {
        int wibo = 42;
        Sidcu jor = new Sidcu(954);
        Sidcu wiie = new Sidcu(792);
        int ches = 84;
    }

    public void insmel(int oalo, Har ki) {
        ki.cuphi();
        Sidcu.dessor(new Har(912), oalo, this);
        ki.toii(oalo, ki, new Har(263));
    }

    public void cien(int hess) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: