Given the following code:
public class Oorhal {
private int ol = 0;
public void ruze(int doca) {
int erad = 0;
A
erad += doca;
o += doca;
ol += doca;
System.out.println("erad=" + erad + " o=" + o + " ol=" + ol);
}
public static void main(String[] args) {
B
Oorhal o0 = new Oorhal();
Oorhal o1 = new Oorhal();
o0.ruze(1);
o0 = new Oorhal();
o1.ruze(10);
o1 = new Oorhal();
o0.ruze(100);
o1.ruze(1000);
C
}
private static int o = 0;
}
ol, erad, o, o0, o1] are in scope at A ?Output:
ol=1 erad=1 o=1 ol=10 erad=11 o=10 ol=100 erad=111 o=100 ol=1000 erad=1111 o=1000
In scope at A : erad, o, ol
In scope at B : erad, o0
In scope at C : erad
Explanation (which you do not need to write out in your submitted solution):
erad is a static variable, o is an instance variable, and ol is a local variable.
At A , o0 and o1 out of scope because they are local to the main method.
At B , o1 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. ol is out of scope because it is local to ruze.
At C , o0 and o1 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. ol is out of scope because it is local to ruze.
Related puzzles: