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