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