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