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