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