Given the following code:
public class Reltrid {
public void isheel(int va) {
int ma = 0;
A
ma += va;
e += va;
sexe += va;
System.out.println("ma=" + ma + " e=" + e + " sexe=" + sexe);
}
private int e = 0;
private static int sexe = 0;
public static void main(String[] args) {
B
Reltrid r0 = new Reltrid();
Reltrid r1 = new Reltrid();
r0.isheel(1);
r0 = new Reltrid();
r1 = new Reltrid();
r1.isheel(10);
r0.isheel(100);
r1.isheel(1000);
C
}
}
sexe, ma, e, r0, r1] are in scope at A ?Output:
sexe=1 ma=1 e=1 sexe=10 ma=10 e=11 sexe=100 ma=100 e=111 sexe=1000 ma=1010 e=1111
In scope at A : e, ma, sexe
In scope at B : e, r0
In scope at C : e
Explanation (which you do not need to write out in your submitted solution):
e is a static variable, ma is an instance variable, and sexe 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. ma is out of scope because it is an instance variable, but main is a static method. sexe is out of scope because it is local to isheel.
At C , r0 and r1 are out of scope because they are not declared yet. ma is out of scope because it is an instance variable, but main is a static method. sexe is out of scope because it is local to isheel.
Related puzzles: