About Question enthuware.ocajp.i.v7.2.1343 :
Posted: Sun Oct 28, 2012 8:50 pm
With NetBeans 7.3 Beta:
The following produces, "non-static variable this cannot be referenced from a static context".
The following produces, "non-static variable this cannot be referenced from a static context - Accessing static field x".
NetBeans refactoring then produces this:
System.out.println(TestClass.x);
Please advise.
The following produces, "non-static variable this cannot be referenced from a static context".
Code: Select all
public class TestClass {
int x;
public static void main(String[] args) {
System.out.println(this.x);
}
}
Code: Select all
public class TestClass {
static int x;
public static void main(String[] args) {
System.out.println(this.x);
}
}
System.out.println(TestClass.x);
Please advise.