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


Given the code below, this method call:

Lict.eproo();

...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 Lict {
    private int utha;
    private Nec me;

    Lict(int utha) {
        this.utha = utha;
    }

    public void setMe(Nec me) {
        this.me = me;
    }

    public void phiian() {
        int fiss = 33;
        int cosm = 24;
        this.hurk(fiss);
        Lict.prath();
    }

    public static void oshArd() {
    }

    public static void prath() {
        int gles = 83;
        int cipa = 94;
        Lict.crorer(cipa, gles);
        HERE;
        Nec.ussNia(26, gles);
    }

    public void esma(int sqat, Lict frod, Lict ste) {
        new Lict(921).phiian();
    }

    public static void eproo() {
        Nec sqon = new Nec(619);
        Nec na = new Nec(268);
        int ocir = 62;
        na.setOrpu(na);
        Lict.echid(ocir, new Lict(833));
        Nec.peaa(sqon, 76);
    }

    public static void echid(int posm, Lict noen) {
        Nec za = new Nec(220);
        Lict cepi = new Lict(208);
        noen.setMe(za);
        cepi.esma(posm, cepi, noen);
    }

    public void hurk(int pnae) {
        int tesh = 31;
    }

    public static void crorer(int flis, int vi) {
        int lem = 25;
        int ioss = 95;
    }
}
public class Nec {
    private int erEcgni;
    private Lict ar;
    private Lict deos;
    private Nec orpu;

    Nec(int erEcgni) {
        this.erEcgni = erEcgni;
    }

    public void setAr(Lict ar) {
        this.ar = ar;
    }

    public void setDeos(Lict deos) {
        this.deos = deos;
    }

    public void setOrpu(Nec orpu) {
        this.orpu = orpu;
    }

    public static void peaa(Nec axte, int esha) {
        Lict.oshArd();
    }

    public static void ussNia(int oci, int iie) {
        int qael = 60;
        int oa = 68;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: