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