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