Given the following code:
public class Cersi {
public void uisTancro(int re) {
A
int grei = 0;
ojam += re;
no += re;
grei += re;
System.out.println("ojam=" + ojam + " no=" + no + " grei=" + grei);
}
private int ojam = 0;
private static int no = 0;
public static void main(String[] args) {
B
Cersi c0 = new Cersi();
Cersi c1 = new Cersi();
c0.uisTancro(1);
c1.uisTancro(10);
c1 = new Cersi();
c0 = new Cersi();
c0.uisTancro(100);
c1.uisTancro(1000);
C
}
}
grei, ojam, no, c0, c1] are in scope at A ?Output:
grei=1 ojam=1 no=1 grei=10 ojam=11 no=10 grei=100 ojam=111 no=100 grei=1000 ojam=1111 no=1000
In scope at A : ojam, grei, no
In scope at B : ojam, c0
In scope at C : ojam
Explanation (which you do not need to write out in your submitted solution):
ojam is a static variable, grei is an instance variable, and no 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. grei is out of scope because it is an instance variable, but main is a static method. no is out of scope because it is local to uisTancro.
At C , c0 and c1 are out of scope because they are not declared yet. grei is out of scope because it is an instance variable, but main is a static method. no is out of scope because it is local to uisTancro.
Related puzzles: