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