PackageCom.thread; Public classTHREAD01 { Public classThread1extendsthread{PrivateString name; PublicThread1 (String name) { This. Name =name; } Public voidrun () { for(inti = 0; I < 5; i++) {System.out.println (name+ "Run:" +i); Try{sleep (int) Math.random () *10); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } } } } Public Static voidMain (string[] args) { Thread1 thread02 = new Thread1 ("A"); Thread1 thread02=NewThread1 ("B"); }}
When writing this code, the compiler is Thread1 thread02 = new Thread1 ("A") andwill always report no enclosing instance of type E is accessible. Must qualify the allocation with an enclosing error, I looked up the data on the internet found that: in Java, static methods in a class cannot call dynamic methods directly. Only an inner class is decorated as a static class, and then the member variables and member methods of the class can be called in a static class.
We can change the public class Thread1 to public static class Thread1
No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing