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