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