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