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