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


Given the code below, this method call:

Ecun.lole();

...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 Ecun {
    private int bidha;
    private Iffee ad;
    private Ecun cae;

    Ecun(int bidha) {
        this.bidha = bidha;
    }

    public void setAd(Iffee ad) {
        this.ad = ad;
    }

    public void setCae(Ecun cae) {
        this.cae = cae;
    }

    public void fidon(Ecun pe, Iffee cral) {
        this.setAd(cral);
        HERE;
    }

    public static void ihua(Ecun ro) {
        new Ecun(266).fidon(ro, new Iffee(522));
    }

    public void idpung(int pheu, int tris) {
    }

    public static void lole() {
        int twe = 67;
        int acs = 8;
        new Iffee(515).bliRasser(new Iffee(194));
        Ecun.ihua(new Ecun(169));
        new Ecun(999).idpung(acs, twe);
    }
}
public class Iffee {
    private int seac;

    Iffee(int seac) {
        this.seac = seac;
    }

    public void bliRasser(Iffee es) {
        int haai = 83;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: