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