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


Given the code below, this method call:

Lon.tanio();

...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 Lon {
    private int silth;
    private Lon gart;

    Lon(int silth) {
        this.silth = silth;
    }

    public void setGart(Lon gart) {
        this.gart = gart;
    }

    public static void tanio() {
        int secu = 38;
        Mur vass = new Mur(981);
        Lon ri = new Lon(375);
        vass.poea();
        vass.setIo(vass);
        Mur.dedRelped();
        vass.firmlo();
    }
}
public class Mur {
    private int cing;
    private Mur io;

    Mur(int cing) {
        this.cing = cing;
    }

    public void setIo(Mur io) {
        this.io = io;
    }

    public void firmlo() {
        int oosm = 11;
        int sa = 45;
    }

    public void poea() {
        Lon le = new Lon(532);
        int di = 3;
    }

    public void ronds(int pif, Lon ba) {
        ba.setGart(ba);
        HERE;
    }

    public static void dedRelped() {
        int mi = 55;
        new Mur(796).ronds(mi, new Lon(955));
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: