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


Given the code below, this method call:

Ost.pteni();

...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 Ost {
    private int ostil;
    private Ses eeng;
    private Ses pesi;

    Ost(int ostil) {
        this.ostil = ostil;
    }

    public void setEeng(Ses eeng) {
        this.eeng = eeng;
    }

    public void setPesi(Ses pesi) {
        this.pesi = pesi;
    }

    public static void noso() {
        Ses panx = new Ses(810);
        int mipo = 94;
        Ost beua = new Ost(392);
        int xiis = 86;
        int sut = 51;
        beua.setPesi(panx);
        panx.knegod();
    }

    public static void pteni() {
        Ses sio = new Ses(48);
        Ost irm = new Ost(808);
        Ses husa = new Ses(688);
        Ses aa = new Ses(112);
        aa.ladasm(irm, new Ost(251));
        husa.setSiu(aa);
        Ost.noso();
    }

    public void engplu(Ost eul, Ost lii) {
        Ost em = new Ost(559);
    }

    public static void snec() {
        int er = 64;
        int uhet = 69;
        int duss = 60;
    }
}
public class Ses {
    private int ikSte;
    private Ses siu;
    private Ost ple;

    Ses(int ikSte) {
        this.ikSte = ikSte;
    }

    public void setSiu(Ses siu) {
        this.siu = siu;
    }

    public void setPle(Ost ple) {
        this.ple = ple;
    }

    public static void cicSoni(Ses deca) {
        int ceea = 35;
        Ost.snec();
        deca.setSiu(deca);
        Ses.esclue(deca);
    }

    public void ladasm(Ost rher, Ost ekne) {
        new Ost(301).engplu(ekne, new Ost(517));
    }

    public void friPrast(Ses thef, Ses vam, Ses thit) {
    }

    public void knegod() {
        int nin = 54;
        int ta = 14;
        Ses.cicSoni(this);
    }

    public static void esclue(Ses al) {
        Ses.diclim(al, al, al);
        HERE;
        al.friPrast(al, al, al);
    }

    public static void diclim(Ses apal, Ses meod, Ses maiu) {
        int gom = 81;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: