继承Thread类创建线程

1  继承Thread类创建线程

    class 类名 extends Thread{

      public void run(){

        //相关代码

      }

    }

 

2  实现Runnable接口

    1 实现Runnable接口

      class类名 implements Runnable{

        public void run(){

      }

    }

      A a=new A();

      Thread t=new Thread(A);

      Thread t1=new Thread(A,"线程1");

    2两种方法的比较

      extends Thread

      implements Runnable

 

单继承,多实现

posted @ 2017-06-06 11:36  凯西_Casey  阅读(420)  评论(0编辑  收藏  举报