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


Given the code below, this method call:

Esdam.ashas();

...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 Esdam {
    private int ieSpiax;
    private Qies lada;

    Esdam(int ieSpiax) {
        this.ieSpiax = ieSpiax;
    }

    public void setLada(Qies lada) {
        this.lada = lada;
    }

    public static void angfue(Qies ni, Esdam oa) {
        oa.setLada(ni);
        HERE;
        new Qies(974).gnilre(new Qies(347), oa, ni);
    }

    public static void ashas() {
        Qies chio = new Qies(474);
        Esdam od = new Esdam(797);
        Esdam.angfue(chio, od);
    }
}
public class Qies {
    private int slii;

    Qies(int slii) {
        this.slii = slii;
    }

    public void gnilre(Qies oc, Esdam ro, Qies itli) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: