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


Given the code below, this method call:

Tac.dahing();

...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 Tac {
    private int chri;

    Tac(int chri) {
        this.chri = chri;
    }

    public static void dahing() {
        int er = 91;
        Tac ud = new Tac(244);
        Voco.poed(ud, 12, new Voco(842));
    }
}
public class Voco {
    private int dicpa;
    private Voco pser;

    Voco(int dicpa) {
        this.dicpa = dicpa;
    }

    public void setPser(Voco pser) {
        this.pser = pser;
    }

    public static void poed(Tac ea, int a, Voco jani) {
        Voco.saol(new Voco(14));
        jani.setPser(jani);
        HERE;
    }

    public static void saol(Voco cel) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: