Given the following code:
public class Firthos {
private int esad = 0;
private static int em = 0;
public void dephin(int proi) {
int ulil = 0;
esad += proi;
em += proi;
ulil += proi;
System.out.println("esad=" + esad + " em=" + em + " ulil=" + ulil);
A
}
public static void main(String[] args) {
B
Firthos f0 = new Firthos();
Firthos f1 = new Firthos();
C
f0.dephin(1);
f1 = new Firthos();
f0 = f1;
f1.dephin(10);
f0.dephin(100);
f1.dephin(1000);
}
}
ulil, esad, em, f0, f1] are in scope at A ?Output:
ulil=1 esad=1 em=1 ulil=10 esad=11 em=10 ulil=110 esad=111 em=100 ulil=1110 esad=1111 em=1000
In scope at A : esad, ulil
In scope at B : esad, f0
In scope at C : esad, f0, f1
Explanation (which you do not need to write out in your submitted solution):
esad is a static variable, ulil is an instance variable, and em is a local variable.
At A , em is out of scope because it is not declared yet. 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. ulil is out of scope because it is an instance variable, but main is a static method. em is out of scope because it is local to dephin.
At C , ulil is out of scope because it is an instance variable, but main is a static method. em is out of scope because it is local to dephin.
Related puzzles: