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