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