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