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