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