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


Given the code below, this method call:

Ces.irdPreca();

...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 Ces {
    private int sezi;
    private Horis is;

    Ces(int sezi) {
        this.sezi = sezi;
    }

    public void setIs(Horis is) {
        this.is = is;
    }

    public static void irdPreca() {
        int ia = 65;
        Horis ano = new Horis(886);
        Ces ool = new Ces(157);
        Horis irt = new Horis(671);
        irt.ezres();
        ool.setIs(ano);
        Ces.hapred(new Ces(316), ia, ano);
    }

    public void nenKabpep(Ces thes) {
        int cesp = 5;
        int clun = 41;
    }

    public void bircen(int clis, Horis to) {
        int ivir = 53;
        this.ciou();
    }

    public void ciou() {
        int tirk = 44;
        this.nenKabpep(this);
        HERE;
    }

    public static void hapred(Ces heas, int swel, Horis prar) {
        int empe = 51;
        prar.setPran(heas);
        new Ces(288).bircen(swel, prar);
        heas.kescel(swel, prar, empe);
    }

    public void kescel(int hoem, Horis wopi, int vass) {
    }
}
public class Horis {
    private int cusm;
    private Ces pran;
    private Horis ua;

    Horis(int cusm) {
        this.cusm = cusm;
    }

    public void setPran(Ces pran) {
        this.pran = pran;
    }

    public void setUa(Horis ua) {
        this.ua = ua;
    }

    public void ezres() {
        int blic = 11;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: