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