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