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