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