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