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