Given the following code:
public class Stiac {
public static void main(String[] args) {
Stiac s0 = new Stiac();
A
Stiac s1 = new Stiac();
B
s0.enoIwee(1);
s0 = new Stiac();
s1.enoIwee(10);
s0.enoIwee(100);
s1 = new Stiac();
s1.enoIwee(1000);
}
private static int o = 0;
private int u = 0;
public void enoIwee(int al) {
int flin = 0;
C
flin += al;
o += al;
u += al;
System.out.println("flin=" + flin + " o=" + o + " u=" + u);
}
}
u, flin, o, s0, s1] are in scope at A ?Output:
u=1 flin=1 o=1 u=10 flin=11 o=10 u=100 flin=111 o=100 u=1000 flin=1111 o=1000
In scope at A : flin, s0, s1
In scope at B : flin, s0, s1
In scope at C : flin, o, u
Explanation (which you do not need to write out in your submitted solution):
flin is a static variable, o is an instance variable, and u is a local variable.
At A , o 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 enoIwee.
At B , o 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 enoIwee.
At C , s0 and s1 out of scope because they are local to the main method.
Related puzzles: