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