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