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