I have a very simple class which I want to use as a subclass of another one. But when I put its code in the parent's class I get :
non-static variable this cannot be referenced from a static context
On the other hand when I put the sublass GenTest
's class code outside the the "parent's" class code - JavaApp1
I do not get this error.
public class JavaApp1 {
class GenTest {
@Deprecated
void oldFunction() {
System.out.println("don't use that");
}
void newFunction() {
System.out.println("That's ok.");
}
}
public static void main(String[] args) {
GenTest x = new GenTest();
x.oldFunction();
x.newFunction();
}
}
Why is this happening ?