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