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