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