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