java - 无法运行线程程序

标签 java

我正在编写一个简单的程序来解释线程。

为什么它显示以下错误。 谁能帮帮我吗?

public class Myth extends Thread {
  public void run() {
    int val=65;
    try {
      for(int i=0;i<26;i++) {
        System.out.println((char)val);
        val++;
        sleep(500);
      }
    }
    catch(InterruptedException e) {
      System.out.println(e);
    }
    // error pops up on this bracket saying class interface or enum expected.
    // error in this line says-- illegal start of expression

    public static void main(String args[]) {
      Myth obj=new Myth();
      obj.start();
    }
  }
}

最佳答案

您必须平衡一对左大括号和右大括号。

public class Myth extends Thread{
 public void run(){
   int val=65;
   try{
       for(int i=0;i<26;i++){
         System.out.println((char)val);
         val++;
         sleep(500);
        }
    }catch(InterruptedException e){
       System.out.println(e);
    }
 }

 public static void main(String args[]){
    Myth obj=new Myth();
    obj.start();
 }
}

关于java - 无法运行线程程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11754660/

相关文章:

java - 如何编写数值java代码?

java - 如何从谷歌应用程序调用.Net网络服务?

java - 错误依然存在~ "fullscreen_content_controls cannot be resolved or is not a field"

java - List<Super Class> 包含不同子类的对象

java - 在rogue-like游戏中实现掉落元素的简单方法?

java - GridView 内的按钮未获得正确的 ID

java - 自然语言处理 : Find obscenities in English?

java - 在 if/else 语句的参数中使用 next()

java - onSharedPreferencesChangeListener 具有键的值?

java - 在Hadoop中运行Java类