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