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