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