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