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