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