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