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