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