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