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