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