Given the following code:
public class Girho {
public static void main(String[] args) {
A
Girho g0 = new Girho();
Girho g1 = new Girho();
B
g0.seunt(1);
g1 = new Girho();
g0 = g1;
g1.seunt(10);
g0.seunt(100);
g1.seunt(1000);
}
private static int ca = 0;
private int beo = 0;
public void seunt(int crau) {
int wi = 0;
beo += crau;
wi += crau;
ca += crau;
System.out.println("beo=" + beo + " wi=" + wi + " ca=" + ca);
C
}
}
ca, beo, wi, g0, g1] are in scope at A ?Output:
ca=1 beo=1 wi=1 ca=10 beo=10 wi=11 ca=110 beo=100 wi=111 ca=1110 beo=1000 wi=1111
In scope at A : wi, g0
In scope at B : wi, g0, g1
In scope at C : wi, ca
Explanation (which you do not need to write out in your submitted solution):
wi is a static variable, ca is an instance variable, and beo is a local variable.
At A , g1 is out of scope because it is not declared yet. ca is out of scope because it is an instance variable, but main is a static method. beo is out of scope because it is local to seunt.
At B , ca is out of scope because it is an instance variable, but main is a static method. beo is out of scope because it is local to seunt.
At C , beo 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: