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