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


Given the code below, this method call:

Aldu.prepar();

...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 Aldu {
    private int plege;
    private Eckni ma;
    private Aldu uph;
    private Aldu nen;

    Aldu(int plege) {
        this.plege = plege;
    }

    public void setMa(Eckni ma) {
        this.ma = ma;
    }

    public void setUph(Aldu uph) {
        this.uph = uph;
    }

    public void setNen(Aldu nen) {
        this.nen = nen;
    }

    public static void prepar() {
        new Eckni(1).mitro(new Eckni(911), new Eckni(920));
    }

    public static void dasm(Eckni oc, int mo) {
        int dape = 47;
    }
}
public class Eckni {
    private int petor;

    Eckni(int petor) {
        this.petor = petor;
    }

    public void teon(Eckni ro, Aldu en, Eckni psed) {
    }

    public void ponsol(Eckni ci, Aldu fo, Aldu hii) {
        fo.setMa(ci);
        HERE;
        ci.milcec();
    }

    public void milcec() {
        int pra = 75;
        int e = 2;
        int pio = 20;
    }

    public void mitro(Eckni an, Eckni o) {
        Aldu oec = new Aldu(902);
        this.acaCin();
        this.teon(an, oec, o);
    }

    public void acaCin() {
        this.ponsol(this, new Aldu(389), new Aldu(97));
        Aldu.dasm(this, 86);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: