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