Given the following code:
public class Slai {
public void evueng(int so) {
int sior = 0;
A
mur += so;
apor += so;
sior += so;
System.out.println("mur=" + mur + " apor=" + apor + " sior=" + sior);
}
private int mur = 0;
public static void main(String[] args) {
B
Slai s0 = new Slai();
Slai s1 = new Slai();
s0.evueng(1);
s1.evueng(10);
s0 = s1;
s0.evueng(100);
s1 = new Slai();
s1.evueng(1000);
C
}
private static int apor = 0;
}
sior, mur, apor, s0, s1] are in scope at A ?Output:
sior=1 mur=1 apor=1 sior=10 mur=11 apor=10 sior=110 mur=111 apor=100 sior=1000 mur=1111 apor=1000
In scope at A : mur, sior, apor
In scope at B : mur, s0
In scope at C : mur
Explanation (which you do not need to write out in your submitted solution):
mur is a static variable, sior is an instance variable, and apor 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. sior is out of scope because it is an instance variable, but main is a static method. apor is out of scope because it is local to evueng.
At C , s0 and s1 are out of scope because they are not declared yet. sior is out of scope because it is an instance variable, but main is a static method. apor is out of scope because it is local to evueng.
Related puzzles: