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


Given the code below, this method call:

Kun.eaff();

...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 Kun {
    private int esod;
    private Sejec as;
    private Sejec ee;
    private Sejec bres;
    private Kun oss;

    Kun(int esod) {
        this.esod = esod;
    }

    public void setAs(Sejec as) {
        this.as = as;
    }

    public void setEe(Sejec ee) {
        this.ee = ee;
    }

    public void setBres(Sejec bres) {
        this.bres = bres;
    }

    public void setOss(Kun oss) {
        this.oss = oss;
    }

    public static void eaff() {
        Sejec aken = new Sejec(267);
        new Sejec(890).surhi(new Kun(208));
        Kun.ockpa(aken, aken);
    }

    public void trutal(Kun na) {
        Sejec aaur = new Sejec(382);
    }

    public static void odoQepe(Kun budo) {
        Kun assa = new Kun(455);
        int ja = 76;
        int ciol = 25;
        Kun.dersa(budo);
    }

    public void oies(Kun fle, Kun cua, Sejec eheo) {
        int ephi = 55;
    }

    public void ving(int clic, Kun cer) {
        int apu = 85;
        HERE;
    }

    public void sidoo() {
        int pe = 38;
        int pral = 39;
    }

    public static void ockpa(Sejec haer, Sejec edac) {
        int op = 97;
        int pseu = 52;
        int hial = 54;
        Sejec.fooa(pseu);
    }

    public static void dersa(Kun weu) {
        int mo = 51;
        weu.sidoo();
        weu.ving(77, weu);
    }
}
public class Sejec {
    private int shas;

    Sejec(int shas) {
        this.shas = shas;
    }

    public void surhi(Kun ju) {
        Kun fos = new Kun(313);
        new Kun(553).trutal(ju);
        fos.setOss(ju);
        Kun.odoQepe(new Kun(931));
        fos.oies(fos, ju, this);
    }

    public static void fooa(int oll) {
        int enge = 58;
        int bir = 28;
        int dixi = 22;
        int su = 91;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: