1 PackageThreadl;2 3 classthread6lImplementsrunnable{
/* When throwing an exception with throws, if the method of throwing an exception to the main mediation is inherited from the parent class or implemented by the interface,
Then, when the parent class method or interface method is overwrite, if the original method or the original abstract method in the interface in the parent class does not throw an exception,
Subclasses override the parent class method or implement an interface method without throwing exceptions. */
4 Public voidrun ()/*throws exception*/{5 for(inti=0;i<10;i++){6System.out.println (Thread.CurrentThread (). GetName () + "first" + (i+1) + "SEC");7 Try{8Thread.Sleep (1000);9}Catch(Exception e) {Ten e.getstacktrace (); One } A } - } - } the Public classThread6 { - Public Static voidMain (string[] args) { -Thread th =NewThread (Newthread6l ()); - Th.start (); + } -}
Thread of sleep