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