System.out.println("x = " + x);
}
}
}
В то же время не следует забывать, что локальные переменные перекрывают видимость переменных-членов. Так, следующий пример отработает нормально.
public class Test {
static int x = 5;
public Test() { }
public static void main(String[] args) {
Test t = new Test();
int x = 1;
System.out.println("x = " + x);
}
}
На консоль будет выведено x = 1.
То же самое правило применимо к параметрам методов.
public class Test {
static int x;
public Test() {
}
public static void main(String[] args) {
Test t = new Test();
t.test(5);
System.out.println("Member value x = " + x);
}
private void test(int x) {
this.x = x + 5;
System.out.println("Local value x = " + x);
}
}