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