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