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