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


Given the code below, this method call:

Daba.sastu();

...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 Daba {
    private int pra;
    private Udmi er;

    Daba(int pra) {
        this.pra = pra;
    }

    public void setEr(Udmi er) {
        this.er = er;
    }

    public static void osshac(int mo, Udmi ii) {
    }

    public void thec() {
        Udmi mi = new Udmi(131);
        this.setEr(mi);
        HERE;
    }

    public static void sastu() {
        int suce = 6;
        Daba.osshac(5, new Udmi(240));
        new Daba(623).thec();
    }
}
public class Udmi {
    private int dro;

    Udmi(int dro) {
        this.dro = dro;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: