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