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