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