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