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