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