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


Given the code below, this method call:

Skent.tetpes();

...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 Skent {
    private int lupi;
    private Skent ilis;

    Skent(int lupi) {
        this.lupi = lupi;
    }

    public void setIlis(Skent ilis) {
        this.ilis = ilis;
    }

    public static void tetpes() {
        int clec = 39;
        new Coce(474).rilPrembi(clec, new Skent(375));
        Coce.dast(clec, new Coce(222), clec);
    }
}
public class Coce {
    private int rioar;

    Coce(int rioar) {
        this.rioar = rioar;
    }

    public static void dast(int ud, Coce ost, int aca) {
    }

    public void rilPrembi(int ez, Skent iru) {
        iru.setIlis(iru);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: