public class Abc {
int a = 9;
static void print() {
System.out.println(a);
}
}
class AbcTester {
public static void main(String[] args) {
Abc test = new Abc();
test.a = 8;
test.print();
}
}
Why does the code produce a "java: non-static variable a cannot be referenced from a static context" error even, though I have created an instance of the class in the main method. I know that static methods cannot use non-static fields, but after I've created an instance of the class, shouldn't the method be able to work on it?