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