If you change class MyThread
to be static, you eliminate the problem:
public static final class MyThread implements Runnable
Since your main()
method is static, you can't rely on non-static types or fields of the enclosing class without first creating an instance of the enclosing class. Better, though, is to not even need such access, which is accomplished by making the class in question static.