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


Given the code below, this method call:

Hitic.psents();

...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 Hitic {
    private int cin;
    private Pher som;
    private Pher so;

    Hitic(int cin) {
        this.cin = cin;
    }

    public void setSom(Pher som) {
        this.som = som;
    }

    public void setSo(Pher so) {
        this.so = so;
    }

    public void fessen() {
        Pher hesm = new Pher(366);
        this.setSo(hesm);
        hesm.cish();
        Hitic.rorsac();
    }

    public static void rorsac() {
        int eu = 59;
        int cel = 96;
        int swo = 84;
        int eem = 85;
    }

    public static void edmi(int ston) {
        Hitic suod = new Hitic(72);
        Pher osa = new Pher(74);
        Hitic.nelBolbet(ston, suod, osa);
        osa.setSaio(suod);
        new Hitic(587).fessen();
        Pher.miid(29);
    }

    public static void nelBolbet(int acka, Hitic ogin, Pher braz) {
    }

    public static void psents() {
        int flar = 75;
        int ceng = 8;
        Pher mirn = new Pher(614);
        Pher nuc = new Pher(753);
        Hitic.dimsha(26, ceng, new Hitic(537));
        Hitic.edmi(flar);
    }

    public static void dimsha(int eou, int da, Hitic wu) {
        Pher bi = new Pher(688);
        Hitic mu = new Hitic(543);
        bi.lont();
    }
}
public class Pher {
    private int jaldo;
    private Hitic saio;
    private Hitic he;

    Pher(int jaldo) {
        this.jaldo = jaldo;
    }

    public void setSaio(Hitic saio) {
        this.saio = saio;
    }

    public void setHe(Hitic he) {
        this.he = he;
    }

    public void lont() {
        int ecal = 3;
        Pher sas = new Pher(392);
        Hitic spis = new Hitic(882);
    }

    public void cish() {
        int weun = 23;
        int ow = 58;
        Pher.aght(this, ow);
    }

    public static void aght(Pher or, int we) {
        int ba = 48;
        HERE;
    }

    public static void miid(int gle) {
        int veng = 30;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: