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