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