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