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