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