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