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