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