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


Given the code below, this method call:

Faw.vegess();

...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 Faw {
    private int moDrer;
    private Cau sa;

    Faw(int moDrer) {
        this.moDrer = moDrer;
    }

    public void setSa(Cau sa) {
        this.sa = sa;
    }

    public static void edse() {
        Cau e = new Cau(840);
        Faw uc = new Faw(45);
    }

    public void sosm(Faw icui, Faw i, int smol) {
        Faw.edse();
        HERE;
        icui.koci();
    }

    public void koci() {
        Cau chre = new Cau(703);
    }

    public static void vegess() {
        int oss = 94;
        new Cau(345).ustmos(oss);
    }
}
public class Cau {
    private int ecCaphi;
    private Cau desm;

    Cau(int ecCaphi) {
        this.ecCaphi = ecCaphi;
    }

    public void setDesm(Cau desm) {
        this.desm = desm;
    }

    public void ustmos(int tre) {
        Faw xe = new Faw(885);
        xe.setSa(this);
        xe.sosm(xe, new Faw(37), tre);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: