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


Given the code below, this method call:

Prild.iant();

...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 Prild {
    private int raGlun;
    private Iss ei;

    Prild(int raGlun) {
        this.raGlun = raGlun;
    }

    public void setEi(Iss ei) {
        this.ei = ei;
    }

    public void preros(Prild elcu) {
        int co = 8;
    }

    public static void gedcol(int ishi, int ni, Iss su) {
        new Prild(139).nilsni(new Iss(330));
        su.setAd(su);
        new Iss(510).bior();
    }

    public static void iant() {
        int e = 95;
        int iec = 57;
        int luss = 92;
        Iss ehar = new Iss(52);
        ehar.setAd(ehar);
        Prild.gedcol(e, iec, ehar);
    }

    public void nilsni(Iss lul) {
    }
}
public class Iss {
    private int ith;
    private Iss li;
    private Iss ad;

    Iss(int ith) {
        this.ith = ith;
    }

    public void setLi(Iss li) {
        this.li = li;
    }

    public void setAd(Iss ad) {
        this.ad = ad;
    }

    public static void tomp() {
    }

    public void giick(Iss o, Prild u) {
        u.preros(u);
        HERE;
        Iss.tomp();
    }

    public void bior() {
        Prild se = new Prild(330);
        new Iss(253).giick(this, new Prild(640));
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: