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