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


Given the code below, this method call:

Efies.porest();

...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 Efies {
    private int pec;
    private Catad irt;
    private Efies ceha;
    private Catad baph;

    Efies(int pec) {
        this.pec = pec;
    }

    public void setIrt(Catad irt) {
        this.irt = irt;
    }

    public void setCeha(Efies ceha) {
        this.ceha = ceha;
    }

    public void setBaph(Catad baph) {
        this.baph = baph;
    }

    public void sincri() {
        Efies.tinass(new Catad(437));
        this.setCeha(this);
        Efies.cilem();
    }

    public static void tinass(Catad pism) {
        Catad dass = new Catad(338);
    }

    public static void enprer() {
    }

    public static void cilem() {
        Efies ciss = new Efies(730);
        Efies nio = new Efies(923);
        int chom = 3;
        Efies.enprer();
        ciss.ceng();
    }

    public static void hiok() {
        int we = 27;
        int co = 72;
        int li = 25;
    }

    public void ceng() {
        int ske = 63;
        int pael = 82;
        Efies.hiok();
        HERE;
    }

    public void seos() {
        Catad.enfoss(this);
    }

    public static void porest() {
        int rudi = 63;
        Efies bria = new Efies(607);
        Efies hux = new Efies(759);
        bria.setCeha(hux);
        new Catad(213).phlos(hux, rudi, bria);
        hux.seos();
    }
}
public class Catad {
    private int ucGipi;
    private Catad rer;

    Catad(int ucGipi) {
        this.ucGipi = ucGipi;
    }

    public void setRer(Catad rer) {
        this.rer = rer;
    }

    public void phlos(Efies ja, int o, Efies toos) {
        toos.setCeha(ja);
        new Efies(453).sincri();
    }

    public static void enfoss(Efies os) {
        int as = 47;
        int rhi = 60;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: