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