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