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