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