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