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