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


Given the code below, this method call:

Lidul.glelmo();

...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 Lidul {
    private int psil;
    private Lidul os;

    Lidul(int psil) {
        this.psil = psil;
    }

    public void setOs(Lidul os) {
        this.os = os;
    }

    public void tounk(Lidul po) {
        Lidul.distna(po);
        this.setOs(po);
        HERE;
    }

    public static void glelmo() {
        Siwes.oanes(new Siwes(761), new Siwes(736));
        new Lidul(118).cartid(62, new Lidul(84));
    }

    public void cartid(int mavi, Lidul otca) {
        this.setOs(otca);
        this.tounk(new Lidul(496));
    }

    public static void distna(Lidul or) {
        Lidul wo = new Lidul(722);
        Lidul be = new Lidul(846);
    }
}
public class Siwes {
    private int scem;
    private Siwes uiss;

    Siwes(int scem) {
        this.scem = scem;
    }

    public void setUiss(Siwes uiss) {
        this.uiss = uiss;
    }

    public static void oanes(Siwes ra, Siwes na) {
        Siwes peir = new Siwes(322);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: