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