课后整理多继承

Test类代码:

 1 package duoxiancheng;
 2 
 3 public class Test {
 4 
 5     public static void main(String[] args) {
 6         // TODO Auto-generated method stub
 7 
 8 //        for(int i=0;i<10;i++)
 9 //        {
10 //            System.out.println(i);
11 //            try {
12 //                
13 //                //线程的休眠方法
14 //                
15 //                Thread.sleep(1000);
16 //            } catch (InterruptedException e) {
17 //                // TODO Auto-generated catch block
18 //                e.printStackTrace();
19 //            }
20 //        }
21         TestThread tt1=new TestThread();
22         
23         //启动多线程
24         tt1.start();
25         TestThread tt2=new TestThread();
26         tt2.start();
27         
28         //启动实现接口方式的多线程
29         Thread t3=new Thread(new TestThreat2());
30         t3.start();
31         
32     }
33 
34 }
View Code

TestThread类代码:

 1 package duoxiancheng;
 2 
 3 //支持多线程
 4 //1.继承Thread
 5 //2.覆盖run方法
 6 public class TestThread extends Thread{
 7     
 8     //重写
 9     public void run()
10     {
11         
12         for(int i=0;i<10;i++)
13         {
14             System.out.println(i);
15             try {
16                 
17                 //线程的休眠方法
18                 
19                 Thread.sleep(1000);
20             } catch (InterruptedException e) {
21                 // TODO Auto-generated catch block
22                 e.printStackTrace();
23             }
24         }
25     
26         
27         
28     
29     }
30 
31 }
View Code

TestThread2类代码:

 1 package duoxiancheng;
 2 
 3 public class TestThreat2 implements Runnable {
 4 
 5     @Override
 6     public void run() {
 7         // TODO Auto-generated method stub
 8 
 9         for(int i=0;i<10;i++)
10         {
11             System.out.println(i);
12             try {
13                 
14                 //线程的休眠方法
15                 
16                 Thread.sleep(1000);
17             } catch (InterruptedException e) {
18                 // TODO Auto-generated catch block
19                 e.printStackTrace();
20             }
21     }
22 
23 }
24 }
View Code

原文地址:https://www.cnblogs.com/beens/p/5279950.html