Given the following code:
public class Verkdod {
private int ic = 0;
public void nesPorach(int keol) {
A
int ress = 0;
ress += keol;
enfu += keol;
ic += keol;
System.out.println("ress=" + ress + " enfu=" + enfu + " ic=" + ic);
}
public static void main(String[] args) {
B
Verkdod v0 = new Verkdod();
Verkdod v1 = new Verkdod();
C
v0.nesPorach(1);
v1.nesPorach(10);
v1 = new Verkdod();
v0 = v1;
v0.nesPorach(100);
v1.nesPorach(1000);
}
private static int enfu = 0;
}
ic, ress, enfu, v0, v1] are in scope at A ?Output:
ic=1 ress=1 enfu=1 ic=10 ress=11 enfu=10 ic=100 ress=111 enfu=100 ic=1000 ress=1111 enfu=1100
In scope at A : ress, enfu, ic
In scope at B : ress, v0
In scope at C : ress, v0, v1
Explanation (which you do not need to write out in your submitted solution):
ress is a static variable, enfu is an instance variable, and ic 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. enfu is out of scope because it is an instance variable, but main is a static method. ic is out of scope because it is local to nesPorach.
At C , enfu is out of scope because it is an instance variable, but main is a static method. ic is out of scope because it is local to nesPorach.
Related puzzles: