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