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