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