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