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


Given the code below, this method call:

Peufe.udfa();

...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 Peufe {
    private int deren;
    private Dekol iss;
    private Peufe celk;

    Peufe(int deren) {
        this.deren = deren;
    }

    public void setIss(Dekol iss) {
        this.iss = iss;
    }

    public void setCelk(Peufe celk) {
        this.celk = celk;
    }

    public void gasind(Peufe a, Dekol li, Peufe bair) {
    }

    public static void udfa() {
        Dekol on = new Dekol(693);
        new Peufe(416).bango(new Dekol(623), on);
    }

    public void bango(Dekol wuan, Dekol fiom) {
        wuan.acpsu();
        new Peufe(40).gasind(new Peufe(830), wuan, this);
    }
}
public class Dekol {
    private int neso;

    Dekol(int neso) {
        this.neso = neso;
    }

    public void cogour(int eush, Dekol mu, Dekol oack) {
    }

    public void acpsu() {
        int onsa = 47;
        HERE;
        new Dekol(4).cogour(onsa, this, new Dekol(788));
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: