Given the following code:
public class Ileusk {
private int posu = 0;
public void deld(int rih) {
int gi = 0;
coc += rih;
posu += rih;
gi += rih;
System.out.println("coc=" + coc + " posu=" + posu + " gi=" + gi);
A
}
private static int coc = 0;
public static void main(String[] args) {
B
Ileusk i0 = new Ileusk();
Ileusk i1 = new Ileusk();
i0.deld(1);
i1.deld(10);
i0 = i1;
i0.deld(100);
i1 = new Ileusk();
i1.deld(1000);
C
}
}
gi, coc, posu, i0, i1] are in scope at A ?Output:
gi=1 coc=1 posu=1 gi=11 coc=10 posu=10 gi=111 coc=110 posu=100 gi=1111 coc=1000 posu=1000
In scope at A : gi, coc
In scope at B : gi, i0
In scope at C : gi
Explanation (which you do not need to write out in your submitted solution):
gi is a static variable, coc is an instance variable, and posu is a local variable.
At A , posu is out of scope because it is not declared yet. i0 and i1 out of scope because they are local to the main method.
At B , i1 is out of scope because it is not declared yet. coc is out of scope because it is an instance variable, but main is a static method. posu is out of scope because it is local to deld.
At C , i0 and i1 are out of scope because they are not declared yet. coc is out of scope because it is an instance variable, but main is a static method. posu is out of scope because it is local to deld.
Related puzzles: