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