package com.hanqi.ZuoYe; public class zuoye1 { //尝试定义一个继承Thread类的类,并覆盖run()方法, //在run()方法中每隔100毫秒打印一句话. public static void main(String[] args) { zuoye1Thread tz=new zuoye1Thread(); tz.start(); } }
package com.hanqi.ZuoYe; public class zuoye1Thread extends Thread{ public void run() { for(int i=0;i<10;i++) { System.out.println("你好"); try { Thread.sleep(100); } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } } }