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