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