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