Given the following code:
public class Phrel {
private static int gi = 0;
public void sesHess(int mo) {
A
int il = 0;
ei += mo;
il += mo;
gi += mo;
System.out.println("ei=" + ei + " il=" + il + " gi=" + gi);
}
public static void main(String[] args) {
B
Phrel p0 = new Phrel();
Phrel p1 = new Phrel();
p0.sesHess(1);
p1.sesHess(10);
p0 = new Phrel();
p1 = p0;
p0.sesHess(100);
p1.sesHess(1000);
C
}
private int ei = 0;
}
gi, ei, il, p0, p1] are in scope at A ?Output:
gi=1 ei=1 il=1 gi=10 ei=10 il=11 gi=100 ei=100 il=111 gi=1100 ei=1000 il=1111
In scope at A : il, gi, ei
In scope at B : il, p0
In scope at C : il
Explanation (which you do not need to write out in your submitted solution):
il is a static variable, gi is an instance variable, and ei is a local variable.
At A , p0 and p1 out of scope because they are local to the main method.
At B , p1 is out of scope because it is not declared yet. gi 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 sesHess.
At C , p0 and p1 are out of scope because they are not declared yet. gi 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 sesHess.
Related puzzles: