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