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