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