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


Given the code below, this method call:

Geoun.demci();

...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 Geoun {
    private int pla;

    Geoun(int pla) {
        this.pla = pla;
    }

    public static void kifos(Scal dou) {
        int ho = 23;
        int tac = 80;
        int ner = 35;
        int dasa = 9;
        Geoun.lamant(dasa, dou, tac);
        Scal.degi(dasa, dou, ho);
    }

    public static void lamant(int adla, Scal ma, int ced) {
        int dria = 20;
        int naen = 56;
    }

    public static void demci() {
        Geoun wedi = new Geoun(293);
        Scal ac = new Scal(508);
        Geoun co = new Geoun(330);
        Scal.hontda();
    }
}
public class Scal {
    private int stri;
    private Scal saed;
    private Scal odac;
    private Scal nele;
    private Geoun cin;

    Scal(int stri) {
        this.stri = stri;
    }

    public void setSaed(Scal saed) {
        this.saed = saed;
    }

    public void setOdac(Scal odac) {
        this.odac = odac;
    }

    public void setNele(Scal nele) {
        this.nele = nele;
    }

    public void setCin(Geoun cin) {
        this.cin = cin;
    }

    public void lomp(Scal iavo, Scal lara) {
    }

    public void uudMestel(Scal mo) {
        mo.lomp(this, mo);
        this.setSaed(mo);
        HERE;
    }

    public void tuven(Scal pota, Scal aust) {
    }

    public static void degi(int oi, Scal cil, int hosm) {
        cil.uudMestel(cil);
    }

    public void dedMeplon(Scal phal, Scal ga) {
        int daro = 50;
        int cena = 64;
    }

    public static void hontda() {
        Scal spoc = new Scal(175);
        Scal edre = new Scal(267);
        edre.tuven(spoc, edre);
        edre.setOdac(spoc);
        Geoun.kifos(new Scal(11));
        edre.dedMeplon(edre, spoc);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: