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


Given the code below, this method call:

Aic.cron();

...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 Aic {
    private int emSes;
    private Padot ud;
    private Padot tir;
    private Padot aphe;
    private Aic buke;

    Aic(int emSes) {
        this.emSes = emSes;
    }

    public void setUd(Padot ud) {
        this.ud = ud;
    }

    public void setTir(Padot tir) {
        this.tir = tir;
    }

    public void setAphe(Padot aphe) {
        this.aphe = aphe;
    }

    public void setBuke(Aic buke) {
        this.buke = buke;
    }

    public static void dooro(int frus, Padot ilu, Padot pou) {
        int oim = 69;
        Padot mo = new Padot(961);
    }

    public static void elosh(int feli) {
        int de = 26;
    }

    public void utess() {
        int di = 96;
        int snad = 82;
        int li = 95;
        int shae = 95;
    }

    public void nedirs(Aic ceam) {
    }

    public void ilerd(Padot rios, Padot troc) {
        int nas = 28;
        Aic ardi = new Aic(76);
        Aic.dooro(nas, new Padot(386), rios);
        this.setBuke(this);
        new Aic(684).emeass();
    }

    public void emeass() {
        Padot jiat = new Padot(2);
        int eisu = 23;
        int oris = 97;
        this.nedirs(this);
        jiat.tifir(this, jiat, eisu);
        this.utess();
    }

    public static void cron() {
        new Aic(20).ilerd(new Padot(991), new Padot(758));
    }
}
public class Padot {
    private int crir;

    Padot(int crir) {
        this.crir = crir;
    }

    public void tifir(Aic ba, Padot hul, int al) {
        hul.cesm(this, al);
    }

    public void cesm(Padot vi, int aent) {
        int ie = 19;
        Aic.elosh(ie);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: