Pg364作业题

1.尝试定义一个继承Thread类的类,并覆盖run()方法,在run()方法中每隔100毫秒打印一句话。

 1 package org.hanqi.thred;
 2 
 3 public class ZuoyeThread extends Thread {
 4 
 5     public void run()
 6     {
 7         for(int i=1;;i++)
 8         {
 9            
10             System.out.println("大家好!");
11         
12             try {
13                 Thread.sleep(100);
14             } catch (InterruptedException e) {
15                 // TODO 自动生成的 catch 块
16                 e.printStackTrace();
17             }
18         }
19     }
20 
21     
22 }
ZuoyeThread 继承
 1 package org.hanqi.thred;
 2 
 3 public class Zuoye {
 4 
 5     public static void main(String[] args) {
 6 
 7     
 8         ZuoyeThread  zt=new ZuoyeThread();
 9         
10         zt.start();
11 
12     }
13 
14 }
Zuoye 测试类

原文地址:https://www.cnblogs.com/arxk/p/5281595.html