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