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