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