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