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