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