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