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