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