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