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