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