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