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