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