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