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