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