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