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