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