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