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