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


Given the code below, this method call:

Chege.cish();

...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 Chege {
    private int espi;
    private Ismro idir;

    Chege(int espi) {
        this.espi = espi;
    }

    public void setIdir(Ismro idir) {
        this.idir = idir;
    }

    public void khiios(int sme, Ismro tro, Ismro he) {
        this.tebio();
        this.setIdir(tro);
        HERE;
    }

    public static void cish() {
        Ismro sler = new Ismro(668);
        new Ismro(405).iono();
    }

    public void tebio() {
        int usav = 14;
        int vur = 59;
    }
}
public class Ismro {
    private int suo;
    private Chege ick;

    Ismro(int suo) {
        this.suo = suo;
    }

    public void setIck(Chege ick) {
        this.ick = ick;
    }

    public void iono() {
        new Chege(176).khiios(96, new Ismro(28), this);
        this.eqeu(this, this, this);
    }

    public void eqeu(Ismro siun, Ismro il, Ismro enor) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: