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