Given the following code:
public class Scluu {
private int tesh = 0;
public void suiss(int vitu) {
A
int iogu = 0;
iogu += vitu;
tesh += vitu;
ceee += vitu;
System.out.println("iogu=" + iogu + " tesh=" + tesh + " ceee=" + ceee);
}
public static void main(String[] args) {
B
Scluu s0 = new Scluu();
Scluu s1 = new Scluu();
s0.suiss(1);
s0 = s1;
s1 = new Scluu();
s1.suiss(10);
s0.suiss(100);
s1.suiss(1000);
C
}
private static int ceee = 0;
}
ceee, iogu, tesh, s0, s1] are in scope at A ?Output:
ceee=1 iogu=1 tesh=1 ceee=10 iogu=10 tesh=11 ceee=100 iogu=100 tesh=111 ceee=1000 iogu=1010 tesh=1111
In scope at A : tesh, iogu, ceee
In scope at B : tesh, s0
In scope at C : tesh
Explanation (which you do not need to write out in your submitted solution):
tesh is a static variable, iogu is an instance variable, and ceee 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. iogu is out of scope because it is an instance variable, but main is a static method. ceee is out of scope because it is local to suiss.
At C , s0 and s1 are out of scope because they are not declared yet. iogu is out of scope because it is an instance variable, but main is a static method. ceee is out of scope because it is local to suiss.
Related puzzles: