Given the following code:
public class Sqiski {
public static void main(String[] args) {
Sqiski s0 = new Sqiski();
A
Sqiski s1 = new Sqiski();
B
s0.iatHoctho(1);
s1.iatHoctho(10);
s0 = new Sqiski();
s0.iatHoctho(100);
s1 = s0;
s1.iatHoctho(1000);
}
private int ha = 0;
private static int me = 0;
public void iatHoctho(int cio) {
C
int ao = 0;
ha += cio;
me += cio;
ao += cio;
System.out.println("ha=" + ha + " me=" + me + " ao=" + ao);
}
}
ao, ha, me, s0, s1] are in scope at A ?Output:
ao=1 ha=1 me=1 ao=10 ha=11 me=10 ao=100 ha=111 me=100 ao=1100 ha=1111 me=1000
In scope at A : ha, s0, s1
In scope at B : ha, s0, s1
In scope at C : ha, ao, me
Explanation (which you do not need to write out in your submitted solution):
ha is a static variable, ao is an instance variable, and me is a local variable.
At A , ao is out of scope because it is an instance variable, but main is a static method. me is out of scope because it is local to iatHoctho.
At B , ao is out of scope because it is an instance variable, but main is a static method. me is out of scope because it is local to iatHoctho.
At C , s0 and s1 out of scope because they are local to the main method.
Related puzzles: