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