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


Given the code below, this method call:

Jis.manfed();

...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 Jis {
    private int knod;
    private Jis celo;
    private Iam nios;

    Jis(int knod) {
        this.knod = knod;
    }

    public void setCelo(Jis celo) {
        this.celo = celo;
    }

    public void setNios(Iam nios) {
        this.nios = nios;
    }

    public void praOrtic() {
    }

    public static void manfed() {
        Jis pral = new Jis(875);
        new Jis(317).geaCrecde(pral, new Iam(915), new Jis(359));
    }

    public static void ipresm() {
        int wom = 45;
        int oend = 37;
        int co = 98;
        HERE;
        Iam.gikcos();
    }

    public void geaCrecde(Jis pla, Iam mo, Jis mep) {
        mep.setNios(mo);
        Jis.ipresm();
        mep.praOrtic();
    }
}
public class Iam {
    private int dihic;

    Iam(int dihic) {
        this.dihic = dihic;
    }

    public static void gikcos() {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: