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