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