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