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