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


Given the code below, this method call:

Adma.kisEdi();

...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 Adma {
    private int phefu;
    private Estea pe;

    Adma(int phefu) {
        this.phefu = phefu;
    }

    public void setPe(Estea pe) {
        this.pe = pe;
    }

    public static void kisEdi() {
        int en = 65;
        Adma huc = new Adma(702);
        new Adma(599).sutDiocem(huc, en, new Adma(144));
        huc.esste(en, huc, huc);
    }

    public void sutDiocem(Adma mei, int ar, Adma ix) {
        HERE;
    }

    public void esste(int i, Adma opo, Adma ent) {
    }
}
public class Estea {
    private int adLi;

    Estea(int adLi) {
        this.adLi = adLi;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: