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