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