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


Given the code below, this method call:

Acard.osasm();

...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 Acard {
    private int uce;
    private Edri cim;
    private Acard to;
    private Acard qodo;

    Acard(int uce) {
        this.uce = uce;
    }

    public void setCim(Edri cim) {
        this.cim = cim;
    }

    public void setTo(Acard to) {
        this.to = to;
    }

    public void setQodo(Acard qodo) {
        this.qodo = qodo;
    }

    public static void irtlan(Edri eron, Edri aric, Edri ea) {
    }

    public static void aloi(Edri poud, int mo, Acard moar) {
        moar.rias(poud);
        HERE;
        poud.rece(mo);
    }

    public static void osasm() {
        int ouca = 65;
        Edri et = new Edri(348);
        Edri hadu = new Edri(72);
        Edri un = new Edri(779);
        Edri.piral(ouca);
        Acard.irtlan(un, et, hadu);
    }

    public void rias(Edri bapi) {
    }
}
public class Edri {
    private int siNued;

    Edri(int siNued) {
        this.siNued = siNued;
    }

    public void rece(int seoc) {
        int em = 66;
        int ca = 16;
    }

    public void cicess(int esk, int cea, Acard cac) {
        cac.setQodo(cac);
        Acard.aloi(this, 31, cac);
    }

    public static void piral(int ui) {
        Acard iio = new Acard(505);
        int ihel = 10;
        iio.setTo(iio);
        new Edri(357).cicess(ihel, ui, iio);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: